public function run($request) { $migrated = FileMigrationHelper::singleton()->run(); if ($migrated) { DB::alteration_message("{$migrated} File DataObjects upgraded", "changed"); } else { DB::alteration_message("No File DataObjects need upgrading", "notice"); } }
/** * Add default records to database. This function is called whenever the * database is built, after the database tables have all been created. Overload * this to add default records when the database is built, but make sure you * call parent::requireDefaultRecords(). * * @uses DataExtension->requireDefaultRecords() */ public function requireDefaultRecords() { $defaultRecords = $this->stat('default_records'); if (!empty($defaultRecords)) { $hasData = DataObject::get_one($this->class); if (!$hasData) { $className = $this->class; foreach ($defaultRecords as $record) { $obj = $this->model->{$className}->newObject($record); $obj->write(); } DB::alteration_message("Added default records to {$className} table", "created"); } } // Let any extentions make their own database default data $this->extend('requireDefaultRecords', $dummy); }
public function requireDefaultRecords() { parent::requireDefaultRecords(); // Check if old file records should be migrated if (!$this->config()->migrate_legacy_file) { return; } $migrated = FileMigrationHelper::singleton()->run(); if ($migrated) { DB::alteration_message("{$migrated} File DataObjects upgraded", "changed"); } }
/** * Cleanup orphaned records in the _versions table * * @param string $baseTable base table to use as authoritative source of records * @param string $childTable Sub-table to clean orphans from */ protected function cleanupVersionedOrphans($baseTable, $childTable) { // Skip if child table doesn't exist if (!DB::get_schema()->hasTable($childTable)) { return; } // Skip if tables are the same if ($childTable === $baseTable) { return; } // Select all orphaned version records $orphanedQuery = SQLSelect::create()->selectField("\"{$childTable}\".\"ID\"")->setFrom("\"{$childTable}\""); // If we have a parent table limit orphaned records // to only those that exist in this if (DB::get_schema()->hasTable($baseTable)) { $orphanedQuery->addLeftJoin($baseTable, "\"{$childTable}\".\"RecordID\" = \"{$baseTable}\".\"RecordID\"\n\t\t\t\t\tAND \"{$childTable}\".\"Version\" = \"{$baseTable}\".\"Version\"")->addWhere("\"{$baseTable}\".\"ID\" IS NULL"); } $count = $orphanedQuery->count(); if ($count > 0) { DB::alteration_message("Removing {$count} orphaned versioned records", "deleted"); $ids = $orphanedQuery->execute()->column(); foreach ($ids as $id) { DB::prepared_query("DELETE FROM \"{$childTable}\" WHERE \"ID\" = ?", array($id)); } } }