diff options
author | Scrutinizer Auto-Fixer <auto-fixer@scrutinizer-ci.com> | 2020-05-26 08:43:40 +0300 |
---|---|---|
committer | Scrutinizer Auto-Fixer <auto-fixer@scrutinizer-ci.com> | 2020-05-26 08:43:40 +0300 |
commit | cf14edf2089040c7cfc2bec347084c30818aba8f (patch) | |
tree | b70de37839c1f3ed062e2d6f9bc694188b2a91b4 /lib/Migration | |
parent | 2396f8326ca2f9d1b2320e6381e26981b902586b (diff) |
Scrutinizer Auto-Fixes
This commit consists of patches automatically generated for this project on https://scrutinizer-ci.com
Diffstat (limited to 'lib/Migration')
-rw-r--r-- | lib/Migration/Version0104Date20200205104800.php | 80 |
1 files changed, 40 insertions, 40 deletions
diff --git a/lib/Migration/Version0104Date20200205104800.php b/lib/Migration/Version0104Date20200205104800.php index ecc00280..32fe2217 100644 --- a/lib/Migration/Version0104Date20200205104800.php +++ b/lib/Migration/Version0104Date20200205104800.php @@ -42,15 +42,15 @@ class Version0104Date20200205104800 extends SimpleMigrationStep { /** @var IConfig */ protected $config; - /** @var array */ - protected $childTables = [ - 'polls_comments', - 'polls_log', - 'polls_notif', - 'polls_options', - 'polls_share', - 'polls_votes', - ]; + /** @var array */ + protected $childTables = [ + 'polls_comments', + 'polls_log', + 'polls_notif', + 'polls_options', + 'polls_share', + 'polls_votes', + ]; /** * @param IDBConnection $connection @@ -62,37 +62,37 @@ class Version0104Date20200205104800 extends SimpleMigrationStep { } - /** - * @param IOutput $output - * @param \Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` - * @param array $options - * @return null - * @since 13.0.0 - */ - public function preSchemaChange(IOutput $output, \Closure $schemaClosure, array $options) { - // delete all orphaned entries by selecting all rows - // those poll_ids are not present in the polls table - // - // we have to use a raw query, because NOT EXISTS is not - // part of doctrine's expression builder - // - // get table prefix, as we are running a raw query - $prefix = $this->config->getSystemValue('dbtableprefix', 'oc_'); - // check for orphaned entries in all tables referencing - // the main polls table - foreach($this->childTables as $tbl) { - $child = "$prefix$tbl"; - $query = "DELETE + /** + * @param IOutput $output + * @param \Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` + * @param array $options + * @return null + * @since 13.0.0 + */ + public function preSchemaChange(IOutput $output, \Closure $schemaClosure, array $options) { + // delete all orphaned entries by selecting all rows + // those poll_ids are not present in the polls table + // + // we have to use a raw query, because NOT EXISTS is not + // part of doctrine's expression builder + // + // get table prefix, as we are running a raw query + $prefix = $this->config->getSystemValue('dbtableprefix', 'oc_'); + // check for orphaned entries in all tables referencing + // the main polls table + foreach($this->childTables as $tbl) { + $child = "$prefix$tbl"; + $query = "DELETE FROM $child WHERE NOT EXISTS ( SELECT NULL FROM {$prefix}polls_polls polls WHERE polls.id = {$child}.poll_id )"; - $stmt = $this->connection->prepare($query); - $stmt->execute(); - } - } + $stmt = $this->connection->prepare($query); + $stmt->execute(); + } + } /** * @param IOutput $output @@ -102,16 +102,16 @@ class Version0104Date20200205104800 extends SimpleMigrationStep { * @since 13.0.0 */ public function changeSchema(IOutput $output, \Closure $schemaClosure, array $options) { - // add an on delete fk contraint to all tables referencing the main polls table + // add an on delete fk contraint to all tables referencing the main polls table /** @var ISchemaWrapper $schema */ $schema = $schemaClosure(); - $eventTable = $schema->getTable('polls_polls'); - foreach($this->childTables as $tbl) { - $table = $schema->getTable($tbl); + $eventTable = $schema->getTable('polls_polls'); + foreach($this->childTables as $tbl) { + $table = $schema->getTable($tbl); - $table->addForeignKeyConstraint($eventTable, ['poll_id'], ['id'], ['onDelete' => 'CASCADE']); - } + $table->addForeignKeyConstraint($eventTable, ['poll_id'], ['id'], ['onDelete' => 'CASCADE']); + } return $schema; } |