. */ namespace Fisharebest\Webtrees\Schema; use Fisharebest\Webtrees\Database; /** * Upgrade the database schema from version 37 to version 38. */ class Migration37 implements MigrationInterface { /** * Upgrade to to the next version */ public function upgrade() { // Move repositories to their own table Database::exec( "CREATE TABLE IF NOT EXISTS `##repository` (" . " repository_id INTEGER AUTO_INCREMENT NOT NULL," . " gedcom_id INTEGER NOT NULL," . " xref VARCHAR(20) NOT NULL," . " gedcom LONGTEXT NOT NULL," . " name VARCHAR(90) NOT NULL," . " address VARCHAR(255) NOT NULL," . " restriction ENUM('', 'confidential', 'privacy', 'none') NOT NULL," . " uid VARCHAR(34) NOT NULL," . " changed_at DATETIME NOT NULL," . " PRIMARY KEY (repository_id)," . " UNIQUE KEY `##repository_ix1` (gedcom_id, xref)," . " UNIQUE KEY `##repository_ix2` (xref, gedcom_id)," . " KEY `##repository_ix3` (name)," . " KEY `##repository_ix4` (address)," . " KEY `##repository_ix5` (restriction)," . " KEY `##repository_ix6` (uid)," . " KEY `##repository_ix7` (changed_at)," . " CONSTRAINT `##repository_fk1` FOREIGN KEY (gedcom_id) REFERENCES `##gedcom` (gedcom_id)" . ") COLLATE utf8_unicode_ci ENGINE=InnoDB" ); Database::exec("START TRANSACTION"); $repositories = Database::prepare("SELECT * FROM `##other` WHERE o_type = 'REPO'")->fetchAll(); foreach ($repositories as $n => $repository) { Database::prepare( "INSERT INTO `##repository` (" . " gedcom_id, xref, gedcom, name, address, restriction, uid, changed_at" . ") VALUES (" . " :gedcom_id, :xref, :gedcom, :name, :address, :restriction, :uid, :changed_at" . ")" )->execute(array( 'gedcom_id' => $repository->o_file, 'xref' => $repository->o_id, 'gedcom' => $repository->o_gedcom, 'name' => '', 'address' => '', 'restriction' => '', 'uid' => '', 'changed_at' => '', )); Database::prepare( "DELETE FROM `##other` WHERE o_file = :gedcom_id AND o_id = :xref" )->execute(array( 'gedcom_id' => $repository->o_file, 'xref' => $repository->o_id, )); if ($n % 500 === 499) { Database::exec("COMMIT"); Database::exec("START TRANSACTION"); } } Database::exec("COMMIT"); } }