@@ -25,81 +25,81 @@ |
||
| 25 | 25 | |
| 26 | 26 | class DatabaseSchemaChecker { |
| 27 | 27 | |
| 28 | - /** |
|
| 29 | - * @param string $appId |
|
| 30 | - * @return array |
|
| 31 | - */ |
|
| 32 | - public function analyse($appId) { |
|
| 33 | - $appPath = \OC_App::getAppPath($appId); |
|
| 34 | - if ($appPath === false) { |
|
| 35 | - throw new \RuntimeException("No app with given id <$appId> known."); |
|
| 36 | - } |
|
| 37 | - |
|
| 38 | - if (!file_exists($appPath . '/appinfo/database.xml')) { |
|
| 39 | - return ['errors' => [], 'warnings' => []]; |
|
| 40 | - } |
|
| 41 | - |
|
| 42 | - libxml_use_internal_errors(true); |
|
| 43 | - $loadEntities = libxml_disable_entity_loader(false); |
|
| 44 | - $xml = simplexml_load_file($appPath . '/appinfo/database.xml'); |
|
| 45 | - libxml_disable_entity_loader($loadEntities); |
|
| 46 | - |
|
| 47 | - |
|
| 48 | - $errors = $warnings = []; |
|
| 49 | - |
|
| 50 | - foreach ($xml->table as $table) { |
|
| 51 | - // Table names |
|
| 52 | - if (strpos((string)$table->name, '*dbprefix*') !== 0) { |
|
| 53 | - $errors[] = 'Database schema error: name of table ' . (string)$table->name . ' does not start with *dbprefix*'; |
|
| 54 | - } |
|
| 55 | - $tableName = substr((string)$table->name, strlen('*dbprefix*')); |
|
| 56 | - if (strpos($tableName, '*dbprefix*') !== false) { |
|
| 57 | - $warnings[] = 'Database schema warning: *dbprefix* should only appear once in name of table ' . (string)$table->name; |
|
| 58 | - } |
|
| 59 | - |
|
| 60 | - if (strlen($tableName) > 27) { |
|
| 61 | - $errors[] = 'Database schema error: Name of table ' . (string)$table->name . ' is too long (' . strlen($tableName) . '), max. 27 characters (21 characters for tables with autoincrement) + *dbprefix* allowed'; |
|
| 62 | - } |
|
| 63 | - |
|
| 64 | - $hasAutoIncrement = false; |
|
| 65 | - |
|
| 66 | - // Column names |
|
| 67 | - foreach ($table->declaration->field as $column) { |
|
| 68 | - if (strpos((string)$column->name, '*dbprefix*') !== false) { |
|
| 69 | - $warnings[] = 'Database schema warning: *dbprefix* should not appear in name of column ' . (string)$column->name . ' on table ' . (string)$table->name; |
|
| 70 | - } |
|
| 71 | - |
|
| 72 | - if (strlen((string)$column->name) > 30) { |
|
| 73 | - $errors[] = 'Database schema error: Name of column ' . (string)$column->name . ' on table ' . (string)$table->name . ' is too long (' . strlen($tableName) . '), max. 30 characters allowed'; |
|
| 74 | - } |
|
| 75 | - |
|
| 76 | - if ($column->autoincrement) { |
|
| 77 | - if ($hasAutoIncrement) { |
|
| 78 | - $errors[] = 'Database schema error: Table ' . (string)$table->name . ' has multiple autoincrement columns'; |
|
| 79 | - } |
|
| 80 | - |
|
| 81 | - if (strlen($tableName) > 21) { |
|
| 82 | - $errors[] = 'Database schema error: Name of table ' . (string)$table->name . ' is too long (' . strlen($tableName) . '), max. 27 characters (21 characters for tables with autoincrement) + *dbprefix* allowed'; |
|
| 83 | - } |
|
| 84 | - |
|
| 85 | - $hasAutoIncrement = true; |
|
| 86 | - } |
|
| 87 | - } |
|
| 88 | - |
|
| 89 | - // Index names |
|
| 90 | - foreach ($table->declaration->index as $index) { |
|
| 91 | - $hasPrefix = strpos((string)$index->name, '*dbprefix*'); |
|
| 92 | - if ($hasPrefix !== false && $hasPrefix !== 0) { |
|
| 93 | - $warnings[] = 'Database schema warning: *dbprefix* should only appear at the beginning in name of index ' . (string)$index->name . ' on table ' . (string)$table->name; |
|
| 94 | - } |
|
| 95 | - |
|
| 96 | - $indexName = $hasPrefix === 0 ? substr((string)$index->name, strlen('*dbprefix*')) : (string)$index->name; |
|
| 97 | - if (strlen($indexName) > 27) { |
|
| 98 | - $errors[] = 'Database schema error: Name of index ' . (string)$index->name . ' on table ' . (string)$table->name . ' is too long (' . strlen($tableName) . '), max. 27 characters + *dbprefix* allowed'; |
|
| 99 | - } |
|
| 100 | - } |
|
| 101 | - } |
|
| 102 | - |
|
| 103 | - return ['errors' => $errors, 'warnings' => $warnings]; |
|
| 104 | - } |
|
| 28 | + /** |
|
| 29 | + * @param string $appId |
|
| 30 | + * @return array |
|
| 31 | + */ |
|
| 32 | + public function analyse($appId) { |
|
| 33 | + $appPath = \OC_App::getAppPath($appId); |
|
| 34 | + if ($appPath === false) { |
|
| 35 | + throw new \RuntimeException("No app with given id <$appId> known."); |
|
| 36 | + } |
|
| 37 | + |
|
| 38 | + if (!file_exists($appPath . '/appinfo/database.xml')) { |
|
| 39 | + return ['errors' => [], 'warnings' => []]; |
|
| 40 | + } |
|
| 41 | + |
|
| 42 | + libxml_use_internal_errors(true); |
|
| 43 | + $loadEntities = libxml_disable_entity_loader(false); |
|
| 44 | + $xml = simplexml_load_file($appPath . '/appinfo/database.xml'); |
|
| 45 | + libxml_disable_entity_loader($loadEntities); |
|
| 46 | + |
|
| 47 | + |
|
| 48 | + $errors = $warnings = []; |
|
| 49 | + |
|
| 50 | + foreach ($xml->table as $table) { |
|
| 51 | + // Table names |
|
| 52 | + if (strpos((string)$table->name, '*dbprefix*') !== 0) { |
|
| 53 | + $errors[] = 'Database schema error: name of table ' . (string)$table->name . ' does not start with *dbprefix*'; |
|
| 54 | + } |
|
| 55 | + $tableName = substr((string)$table->name, strlen('*dbprefix*')); |
|
| 56 | + if (strpos($tableName, '*dbprefix*') !== false) { |
|
| 57 | + $warnings[] = 'Database schema warning: *dbprefix* should only appear once in name of table ' . (string)$table->name; |
|
| 58 | + } |
|
| 59 | + |
|
| 60 | + if (strlen($tableName) > 27) { |
|
| 61 | + $errors[] = 'Database schema error: Name of table ' . (string)$table->name . ' is too long (' . strlen($tableName) . '), max. 27 characters (21 characters for tables with autoincrement) + *dbprefix* allowed'; |
|
| 62 | + } |
|
| 63 | + |
|
| 64 | + $hasAutoIncrement = false; |
|
| 65 | + |
|
| 66 | + // Column names |
|
| 67 | + foreach ($table->declaration->field as $column) { |
|
| 68 | + if (strpos((string)$column->name, '*dbprefix*') !== false) { |
|
| 69 | + $warnings[] = 'Database schema warning: *dbprefix* should not appear in name of column ' . (string)$column->name . ' on table ' . (string)$table->name; |
|
| 70 | + } |
|
| 71 | + |
|
| 72 | + if (strlen((string)$column->name) > 30) { |
|
| 73 | + $errors[] = 'Database schema error: Name of column ' . (string)$column->name . ' on table ' . (string)$table->name . ' is too long (' . strlen($tableName) . '), max. 30 characters allowed'; |
|
| 74 | + } |
|
| 75 | + |
|
| 76 | + if ($column->autoincrement) { |
|
| 77 | + if ($hasAutoIncrement) { |
|
| 78 | + $errors[] = 'Database schema error: Table ' . (string)$table->name . ' has multiple autoincrement columns'; |
|
| 79 | + } |
|
| 80 | + |
|
| 81 | + if (strlen($tableName) > 21) { |
|
| 82 | + $errors[] = 'Database schema error: Name of table ' . (string)$table->name . ' is too long (' . strlen($tableName) . '), max. 27 characters (21 characters for tables with autoincrement) + *dbprefix* allowed'; |
|
| 83 | + } |
|
| 84 | + |
|
| 85 | + $hasAutoIncrement = true; |
|
| 86 | + } |
|
| 87 | + } |
|
| 88 | + |
|
| 89 | + // Index names |
|
| 90 | + foreach ($table->declaration->index as $index) { |
|
| 91 | + $hasPrefix = strpos((string)$index->name, '*dbprefix*'); |
|
| 92 | + if ($hasPrefix !== false && $hasPrefix !== 0) { |
|
| 93 | + $warnings[] = 'Database schema warning: *dbprefix* should only appear at the beginning in name of index ' . (string)$index->name . ' on table ' . (string)$table->name; |
|
| 94 | + } |
|
| 95 | + |
|
| 96 | + $indexName = $hasPrefix === 0 ? substr((string)$index->name, strlen('*dbprefix*')) : (string)$index->name; |
|
| 97 | + if (strlen($indexName) > 27) { |
|
| 98 | + $errors[] = 'Database schema error: Name of index ' . (string)$index->name . ' on table ' . (string)$table->name . ' is too long (' . strlen($tableName) . '), max. 27 characters + *dbprefix* allowed'; |
|
| 99 | + } |
|
| 100 | + } |
|
| 101 | + } |
|
| 102 | + |
|
| 103 | + return ['errors' => $errors, 'warnings' => $warnings]; |
|
| 104 | + } |
|
| 105 | 105 | } |
@@ -35,13 +35,13 @@ discard block |
||
| 35 | 35 | throw new \RuntimeException("No app with given id <$appId> known."); |
| 36 | 36 | } |
| 37 | 37 | |
| 38 | - if (!file_exists($appPath . '/appinfo/database.xml')) { |
|
| 38 | + if (!file_exists($appPath.'/appinfo/database.xml')) { |
|
| 39 | 39 | return ['errors' => [], 'warnings' => []]; |
| 40 | 40 | } |
| 41 | 41 | |
| 42 | 42 | libxml_use_internal_errors(true); |
| 43 | 43 | $loadEntities = libxml_disable_entity_loader(false); |
| 44 | - $xml = simplexml_load_file($appPath . '/appinfo/database.xml'); |
|
| 44 | + $xml = simplexml_load_file($appPath.'/appinfo/database.xml'); |
|
| 45 | 45 | libxml_disable_entity_loader($loadEntities); |
| 46 | 46 | |
| 47 | 47 | |
@@ -49,37 +49,37 @@ discard block |
||
| 49 | 49 | |
| 50 | 50 | foreach ($xml->table as $table) { |
| 51 | 51 | // Table names |
| 52 | - if (strpos((string)$table->name, '*dbprefix*') !== 0) { |
|
| 53 | - $errors[] = 'Database schema error: name of table ' . (string)$table->name . ' does not start with *dbprefix*'; |
|
| 52 | + if (strpos((string) $table->name, '*dbprefix*') !== 0) { |
|
| 53 | + $errors[] = 'Database schema error: name of table '.(string) $table->name.' does not start with *dbprefix*'; |
|
| 54 | 54 | } |
| 55 | - $tableName = substr((string)$table->name, strlen('*dbprefix*')); |
|
| 55 | + $tableName = substr((string) $table->name, strlen('*dbprefix*')); |
|
| 56 | 56 | if (strpos($tableName, '*dbprefix*') !== false) { |
| 57 | - $warnings[] = 'Database schema warning: *dbprefix* should only appear once in name of table ' . (string)$table->name; |
|
| 57 | + $warnings[] = 'Database schema warning: *dbprefix* should only appear once in name of table '.(string) $table->name; |
|
| 58 | 58 | } |
| 59 | 59 | |
| 60 | 60 | if (strlen($tableName) > 27) { |
| 61 | - $errors[] = 'Database schema error: Name of table ' . (string)$table->name . ' is too long (' . strlen($tableName) . '), max. 27 characters (21 characters for tables with autoincrement) + *dbprefix* allowed'; |
|
| 61 | + $errors[] = 'Database schema error: Name of table '.(string) $table->name.' is too long ('.strlen($tableName).'), max. 27 characters (21 characters for tables with autoincrement) + *dbprefix* allowed'; |
|
| 62 | 62 | } |
| 63 | 63 | |
| 64 | 64 | $hasAutoIncrement = false; |
| 65 | 65 | |
| 66 | 66 | // Column names |
| 67 | 67 | foreach ($table->declaration->field as $column) { |
| 68 | - if (strpos((string)$column->name, '*dbprefix*') !== false) { |
|
| 69 | - $warnings[] = 'Database schema warning: *dbprefix* should not appear in name of column ' . (string)$column->name . ' on table ' . (string)$table->name; |
|
| 68 | + if (strpos((string) $column->name, '*dbprefix*') !== false) { |
|
| 69 | + $warnings[] = 'Database schema warning: *dbprefix* should not appear in name of column '.(string) $column->name.' on table '.(string) $table->name; |
|
| 70 | 70 | } |
| 71 | 71 | |
| 72 | - if (strlen((string)$column->name) > 30) { |
|
| 73 | - $errors[] = 'Database schema error: Name of column ' . (string)$column->name . ' on table ' . (string)$table->name . ' is too long (' . strlen($tableName) . '), max. 30 characters allowed'; |
|
| 72 | + if (strlen((string) $column->name) > 30) { |
|
| 73 | + $errors[] = 'Database schema error: Name of column '.(string) $column->name.' on table '.(string) $table->name.' is too long ('.strlen($tableName).'), max. 30 characters allowed'; |
|
| 74 | 74 | } |
| 75 | 75 | |
| 76 | 76 | if ($column->autoincrement) { |
| 77 | 77 | if ($hasAutoIncrement) { |
| 78 | - $errors[] = 'Database schema error: Table ' . (string)$table->name . ' has multiple autoincrement columns'; |
|
| 78 | + $errors[] = 'Database schema error: Table '.(string) $table->name.' has multiple autoincrement columns'; |
|
| 79 | 79 | } |
| 80 | 80 | |
| 81 | 81 | if (strlen($tableName) > 21) { |
| 82 | - $errors[] = 'Database schema error: Name of table ' . (string)$table->name . ' is too long (' . strlen($tableName) . '), max. 27 characters (21 characters for tables with autoincrement) + *dbprefix* allowed'; |
|
| 82 | + $errors[] = 'Database schema error: Name of table '.(string) $table->name.' is too long ('.strlen($tableName).'), max. 27 characters (21 characters for tables with autoincrement) + *dbprefix* allowed'; |
|
| 83 | 83 | } |
| 84 | 84 | |
| 85 | 85 | $hasAutoIncrement = true; |
@@ -88,14 +88,14 @@ discard block |
||
| 88 | 88 | |
| 89 | 89 | // Index names |
| 90 | 90 | foreach ($table->declaration->index as $index) { |
| 91 | - $hasPrefix = strpos((string)$index->name, '*dbprefix*'); |
|
| 91 | + $hasPrefix = strpos((string) $index->name, '*dbprefix*'); |
|
| 92 | 92 | if ($hasPrefix !== false && $hasPrefix !== 0) { |
| 93 | - $warnings[] = 'Database schema warning: *dbprefix* should only appear at the beginning in name of index ' . (string)$index->name . ' on table ' . (string)$table->name; |
|
| 93 | + $warnings[] = 'Database schema warning: *dbprefix* should only appear at the beginning in name of index '.(string) $index->name.' on table '.(string) $table->name; |
|
| 94 | 94 | } |
| 95 | 95 | |
| 96 | - $indexName = $hasPrefix === 0 ? substr((string)$index->name, strlen('*dbprefix*')) : (string)$index->name; |
|
| 96 | + $indexName = $hasPrefix === 0 ? substr((string) $index->name, strlen('*dbprefix*')) : (string) $index->name; |
|
| 97 | 97 | if (strlen($indexName) > 27) { |
| 98 | - $errors[] = 'Database schema error: Name of index ' . (string)$index->name . ' on table ' . (string)$table->name . ' is too long (' . strlen($tableName) . '), max. 27 characters + *dbprefix* allowed'; |
|
| 98 | + $errors[] = 'Database schema error: Name of index '.(string) $index->name.' on table '.(string) $table->name.' is too long ('.strlen($tableName).'), max. 27 characters + *dbprefix* allowed'; |
|
| 99 | 99 | } |
| 100 | 100 | } |
| 101 | 101 | } |