2929
3030class TableManager extends DbManager {
3131
32- // private string $dbPrefix;
33- // private Schema|ISchemaWrapper $schema;
34-
3532 /** @psalm-suppress PossiblyUnusedMethod */
3633 public function __construct (
3734 protected IConfig $ config ,
@@ -41,27 +38,8 @@ public function __construct(
4138 private VoteMapper $ voteMapper ,
4239 ) {
4340 parent ::__construct ($ config , $ connection );
44- // $this->dbPrefix = $this->config->getSystemValue('dbtableprefix', 'oc_');
4541 }
4642
47- // public function setSchema(Schema|ISchemaWrapper &$schema): void {
48- // $this->schema = $schema;
49- // }
50-
51- // public function createSchema(): Schema {
52- // $this->schema = $this->connection->createSchema();
53- // return $this->schema;
54- // }
55- // public function migrateToSchema() : void {
56- // // Schema must be of class Schema
57- // $this->needsSchema(iSchemWrapperClass: false);
58- // $this->connection->migrateToSchema($this->schema);
59- // }
60-
61- // public function setConnection(IDBConnection &$connection): void {
62- // $this->connection = $connection;
63- // }
64-
6543 /**
6644 * @return string[]
6745 *
@@ -464,23 +442,22 @@ public function fixNullishShares(): array {
464442 $ query = $ this ->connection ->getQueryBuilder ();
465443 $ schema = $ this ->connection ->createSchema ();
466444
467- if (!$ schema ->hasTable (Share::TABLE )) {
468- $ messages [] = 'Table ' . Share::TABLE . ' does not exist ' ;
445+ if (!$ schema ->hasTable ($ this -> dbPrefix . Share::TABLE )) {
446+ $ messages [] = 'Table ' . $ this -> dbPrefix . Share::TABLE . ' does not exist ' ;
469447 return $ messages ;
470448 }
471449
472- $ table = $ schema ->getTable (Share::TABLE );
450+ $ table = $ schema ->getTable ($ this -> dbPrefix . Share::TABLE );
473451
474452 if ($ table ->hasColumn ('group_id ' )) {
475453 // replace all nullish group_ids with 0 in share table
476454 $ query ->update (Share::TABLE )
477455 ->set ('group_id ' , $ query ->createNamedParameter (0 , IQueryBuilder::PARAM_INT ))
478456 ->where ($ query ->expr ()->isNull ('group_id ' ));
479-
480457 $ count = $ query ->executeStatement ();
481458
482459 if ($ count > 0 ) {
483- $ messages [] = 'Updated ' . $ count . ' shares and set group_id to 0 for nullish values ' ;
460+ $ messages [] = 'Updated ' . $ count . ' shares with nullish group_id and set group_id to 0 ' ;
484461 }
485462 }
486463
@@ -506,6 +483,12 @@ public function fixNullishShares(): array {
506483 public function fixNullishPollGroupRelations (): array {
507484 $ messages = [];
508485 $ query = $ this ->connection ->getQueryBuilder ();
486+ $ schema = $ this ->connection ->createSchema ();
487+
488+ if (!$ schema ->hasTable ($ this ->dbPrefix . PollGroup::RELATION_TABLE )) {
489+ $ messages [] = 'Table ' . $ this ->dbPrefix . PollGroup::RELATION_TABLE . ' does not exist ' ;
490+ return $ messages ;
491+ }
509492
510493 // replace all nullish group_ids with 0 in share table
511494 $ query ->update (PollGroup::RELATION_TABLE )
@@ -611,37 +594,4 @@ public function migrateOptionsToHash(): array {
611594 }
612595 return $ messages ;
613596 }
614-
615- // protected function getTableName(string $tableName): ?string {
616- // if ($this->schema instanceof Schema) {
617- // // If the schema is an instance of Schema, we need to prefix the table name
618- // return $this->config->getSystemValue('dbtableprefix', 'oc_') . $tableName;
619- // }
620- // return $tableName;
621- // }
622-
623- // protected function needsSchema(bool $schemaClass = true, bool $iSchemWrapperClass = true): void {
624- // if (($this->schema instanceof Schema) && $schemaClass) {
625- // return;
626- // }
627-
628- // if (($this->schema instanceof ISchemaWrapper) && $iSchemWrapperClass) {
629- // return;
630- // }
631-
632- // if ($schemaClass && $iSchemWrapperClass) {
633- // // If the schema is not set or not an instance of Schema or ISchemaWrapper, throw an exception
634- // throw new Exception('Schema is not set or not an instance of Schema or ISchemaWrapper');
635- // }
636- // if ($schemaClass) {
637- // // If the schema is not set or not an instance of Schema, throw an exception
638- // throw new Exception('Schema is not set or not an instance of Schema');
639- // }
640- // if ($iSchemWrapperClass) {
641- // // If the schema is not set or not an instance of ISchemaWrapper, throw an exception
642- // throw new Exception('Schema is not set or not an instance of ISchemaWrapper');
643- // }
644- // throw new Exception('Unexpected. Schema is an instance of ' . get_class($this->schema));
645- // }
646-
647597}
0 commit comments