Author: sevein
Date: Fri Jul 20 18:27:41 2012
New Revision: 11947

Log:
More progress in arUpgrader110, including schema updates

Modified:
   trunk/lib/task/migrate/QubitMigrate.class.php
   trunk/lib/task/migrate/arUpgradeSqlTask.class.php
   trunk/lib/task/migrate/arUpgrader110.class.php

Modified: trunk/lib/task/migrate/QubitMigrate.class.php
==============================================================================
--- trunk/lib/task/migrate/QubitMigrate.class.php       Fri Jul 20 13:24:38 
2012        (r11946)
+++ trunk/lib/task/migrate/QubitMigrate.class.php       Fri Jul 20 18:27:41 
2012        (r11947)
@@ -552,9 +552,7 @@
         // Get new autonumeric
         $last = QubitPdo::fetchOne('SELECT (MAX(id) + 1) AS last FROM 
object')->last;
 
-        $foreignKeys = self::findForeignKeys(array(
-          QubitObject::TABLE_NAME,
-          QubitMenu::TABLE_NAME), $configuration);
+        $foreignKeys = self::findForeignKeys(array(QubitObject::TABLE_NAME, 
QubitMenu::TABLE_NAME), $configuration);
 
         foreach ($foreignKeys as $item)
         {
@@ -579,6 +577,52 @@
     $connection->commit();
   }
 
+  public static function addColumn($table, $column, array $options = array())
+  {
+    $sql = "ALTER TABLE $table ADD $column";
+
+    // Position of the new column
+    if (isset($options['after']))
+    {
+      $sql .= " AFTER $options[after]";
+    }
+    else if (isset($options['before']))
+    {
+      $sql .= " BEFORE $options[before]";
+    }
+    else if (isset($options['first']))
+    {
+      $sql .= " FIRST";
+    }
+
+    // Foreign key
+    if (isset($options['fk']))
+    {
+    }
+
+    // Index
+    if (isset($options['idx']))
+    {
+    }
+
+    $connection = Propel::getConnection();
+
+    $connection->beginTransaction();
+
+    try
+    {
+      $connection->exec($sql);
+    }
+    catch (Exception $e)
+    {
+      $connection->rollback();
+
+      throw $e;
+    }
+
+    $connection->commit();
+  }
+
   public static function dropColumn($table, $column)
   {
     $connection = Propel::getConnection();
@@ -648,4 +692,28 @@
 
     $connection->commit();
   }
+
+  public static function dropTable($table)
+  {
+    $connection = Propel::getConnection();
+
+    $connection->beginTransaction();
+
+    try
+    {
+      $connection->exec('SET FOREIGN_KEY_CHECKS = 0');
+
+      $connection->exec("DROP TABLE IF EXISTS $table");
+
+      $connection->exec('SET FOREIGN_KEY_CHECKS = 1');
+    }
+    catch (Exception $e)
+    {
+      $connection->rollback();
+
+      throw $e;
+    }
+
+    $connection->commit();
+  }
 }

Modified: trunk/lib/task/migrate/arUpgradeSqlTask.class.php
==============================================================================
--- trunk/lib/task/migrate/arUpgradeSqlTask.class.php   Fri Jul 20 13:24:38 
2012        (r11946)
+++ trunk/lib/task/migrate/arUpgradeSqlTask.class.php   Fri Jul 20 18:27:41 
2012        (r11947)
@@ -135,6 +135,7 @@
       try
       {
         $this->logSection('upgrade-sql', sprintf('Upgrading from Release %s', 
$class::MILESTONE));
+
         while ($class->up($version, $this->configuration))
         {
           // Update version in database
@@ -144,7 +145,7 @@
       }
       catch (Exception $e)
       {
-        $this->logSection('upgrade-sql', sprintf('The task failed while trying 
to upgrade to v'.$version + 1));
+        $this->logSection('upgrade-sql', sprintf('The task failed while trying 
to upgrade to v%s', $version + 1));
 
         throw $e;
       }

Modified: trunk/lib/task/migrate/arUpgrader110.class.php
==============================================================================
--- trunk/lib/task/migrate/arUpgrader110.class.php      Fri Jul 20 13:24:38 
2012        (r11946)
+++ trunk/lib/task/migrate/arUpgrader110.class.php      Fri Jul 20 18:27:41 
2012        (r11947)
@@ -32,6 +32,11 @@
 
   public function up($version, $configuration)
   {
+    if (self::INIT_VERSION == $version)
+    {
+      $this->updateSchema($configuration);
+    }
+
     switch ($version)
     {
       // Add accession module menu entry, internal taxonomies,
@@ -40,20 +45,18 @@
         // Add accession mask user setting
         $setting = new QubitSetting;
         $setting->name  = 'accession_mask';
-        $setting->value = '%Y-%m-%d/#i';
         $setting->editable = 1;
-        $setting->deleteable = 0;
         $setting->sourceCulture = 'en';
+        $setting->value = '%Y-%m-%d/#i';
         $setting->culture = 'en';
         $setting->save();
 
         // Add accession counter setting
         $setting = new QubitSetting;
         $setting->name  = 'accession_counter';
-        $setting->value = '0';
         $setting->editable = 1;
-        $setting->deleteable = 0;
         $setting->sourceCulture = 'en';
+        $setting->value = '0';
         $setting->culture = 'en';
         $setting->save();
 
@@ -98,9 +101,9 @@
         $node->name = 'manage';
         $node->path = 'accession/browse';
         $node->sourceCulture = 'en';
-        $node->label = 'Manage';
 
         foreach (array(
+          'en' => 'Manage',
           'es' => 'Administrar',
           'fr' => 'Gérer',
           'pl' => 'Zarządzanie',
@@ -115,12 +118,17 @@
 
         QubitMigrate::addMenu($node, $configuration);
 
-        // Introduce it before "taxonomies"
-        if (null !== $target = QubitMenu::getByName('taxonomies'))
+        // Introduce it after "add"
+        if (null !== $target = QubitMenu::getByName('add'))
         {
-          $node->moveToPrevSiblingOf($target);
+          $node->moveToNextSiblingOf($target);
         }
 
+        // Move taxonomies under "Manage"
+        $node = QubitMenu::getByName('taxonomies');
+        $node->parentId = QubitMenu::MANAGE_ID;
+        $node->save();
+
         // Create manage accession menu node
         $node = new QubitMenu;
         $node->parentId = QubitMenu::MANAGE_ID;
@@ -128,6 +136,7 @@
         $node->path = 'accession/browse';
         $node->sourceCulture = 'en';
         $node->label = 'Accession records';
+        $node->culture = 'en';
 
         foreach (array(
           'es' => 'Registros de adhesiones',
@@ -157,6 +166,7 @@
         $node->path = 'donor/browse';
         $node->sourceCulture = 'en';
         $node->label = 'Donors';
+        $node->culture = 'en';
 
         foreach (array(
           'es' => 'Donantes',
@@ -174,10 +184,10 @@
 
         $node->save();
 
-        // Introduce it before "taxonomies"
-        if (null !== $target = QubitMenu::getByName('taxonomies'))
+        // Introduce it before "accessions"
+        if (null !== $target = QubitMenu::getByName('accessions'))
         {
-          $node->moveToPrevSiblingOf($target);
+          $node->moveToNextSiblingOf($target);
         }
 
         // Create manage rightsholder menu node
@@ -186,7 +196,8 @@
         $node->name = 'rightsholders';
         $node->path = 'rightsholder/browse';
         $node->sourceCulture = 'en';
-        $node->value = 'Rights holders';
+        $node->label = 'Rights holders';
+        $node->culture = 'en';
 
         foreach (array(
           'es' => 'Titulares de derechos',
@@ -465,12 +476,6 @@
       // recorded, update checksum_type column
       case 64:
 
-        // Drop column checksum_type_id
-        QubitMigrate::dropColumn(QubitDigitalObject::TABLE_NAME, 
'checksum_type_id');
-
-        // Add column checksumn_type
-        QubitPdo::modify('ALTER TABLE digital_object ADD `checksum_type` 
VARCHAR(255) NOT NULL BEFORE `parent_id`');
-
         // Set value md5 in some cases
         $sql  = 'UPDATE '.QubitDigitalObject::TABLE_NAME;
         $sql .= ' SET '.QubitDigitalObject::CHECKSUM_TYPE.' = "md5"';
@@ -576,7 +581,7 @@
         }
 
         $criteria = new Criteria;
-        $criteria->add(QubitDigitalObject::INFORMATION_OBJECT_ID, 
Criteria::NOT_NULL);
+        $criteria->add(QubitDigitalObject::INFORMATION_OBJECT_ID, 
Criteria::ISNOTNULL);
         foreach (QubitDigitalObject::get($criteria) as $item)
         {
           $io = QubitInformationObject::getById($item->informationObjectId);
@@ -656,7 +661,7 @@
 
       // Add default value for repository.upload_limit column
       case 71:
-        $sql = 'UPDATE '.QubitRepository::TABLE_NAME.' SET upload_limit = 
"-1"';
+        $sql = 'UPDATE '.QubitRepository::TABLE_NAME.' SET upload_limit = -1';
         QubitPdo::modify($sql);
 
         break;
@@ -696,7 +701,7 @@
 
       // Migrate to sfCaribou theme to users that are currently using sfClassic
       case 73:
-        if (null !== $setting = QubitSetting::getByName('plugins'))
+        if (null !== $setting = QubitSetting::getSettingByName('plugins'))
         {
           $plugin = 'sfClassicPlugin';
           $replacement = 'sfCaribouPlugin';
@@ -718,7 +723,7 @@
 
       // Ensure all information objects get an explicit publication status
       case 74:
-        $criteria = new QubitInformationObject;
+        $criteria = new Criteria;
         $criteria->add(QubitInformationObject::ID, 
QubitInformationObject::ROOT_ID, Criteria::NOT_EQUAL);
         foreach (QubitInformationObject::get($criteria) as $item)
         {
@@ -746,36 +751,323 @@
       // Return false if no upgrade available
       default:
 
-        // Drop unneeded tables
-        foreach array(
-          'historical_event',
-          'map',
-          'map_i18n',
-          'place',
-          'place_i18n',
-          'place_map_relation',
-          'system_event_table') as $item)
-        {
-          QubitMigrate::dropTable($item);
-        }
-
-        // Drop updated_at and created_at columns
-        foreach array(
-          'menu',
-          'note',
-          'other_name',
-          'property',
-          'status'
-          'taxonomy'
-          ) as $item)
-        {
-          QubitMigrate::dropColumn($item, 'updated_at');
-          QubitMigrate::dropColumn($item, 'created_at');
-        }
-
         return false;
     }
 
     return true;
   }
+
+  public function updateSchema($configuration)
+  {
+    // Add ON DELETE CASCADE in slug.object_id
+    $sql = "ALTER TABLE `slug`
+              DROP FOREIGN KEY `slug_FK_1`,
+              ADD FOREIGN KEY (`object_id`)
+                REFERENCES  `qubit`.`object` (`id`)
+                ON DELETE CASCADE ON UPDATE RESTRICT;";
+    QubitPdo::modify($sql);
+
+    // Drop parent_id, lft and rgt columns from table note
+    QubitMigrate::dropColumn(QubitNote::TABLE_NAME, 'parent_id');
+    QubitMigrate::dropColumn(QubitNote::TABLE_NAME, 'lft');
+    QubitMigrate::dropColumn(QubitNote::TABLE_NAME, 'rgt');
+
+    // Add start_date and end_date in table other_name
+    QubitMigrate::addColumn(QubitOtherName::TABLE_NAME, 'start_date DATE', 
array('after' => 'type_id'));
+    QubitMigrate::addColumn(QubitOtherName::TABLE_NAME, 'end_date DATE', 
array('after' => 'start_date'));
+
+    // Add dates column to other_name_i18n
+    QubitMigrate::addColumn(QubitOtherNameI18n::TABLE_NAME, 'dates TEXT', 
array('after' => 'note'));
+
+    // Add relation.source_culture
+    QubitMigrate::addColumn(QubitRelation::TABLE_NAME, 'source_culture 
VARCHAR(7) NOT NULL', array('after' => 'end_date'));
+
+    // Add repository.upload_limit
+    QubitMigrate::addColumn(QubitRepository::TABLE_NAME, 'upload_limit FLOAT', 
array('after' => 'desc_identifier'));
+
+    // Drop column digita_object.checksum_type_id
+    QubitMigrate::dropColumn(QubitDigitalObject::TABLE_NAME, 
'checksum_type_id');
+
+    // Add column digital_object.checksumn_type
+    QubitPdo::modify('ALTER TABLE digital_object ADD `checksum_type` 
VARCHAR(50) AFTER `checksum`');
+
+    // Create relation_i18n
+    $sql = <<<sql
+
+CREATE TABLE `relation_i18n`
+(
+        `description` TEXT,
+        `date` VARCHAR(255),
+        `id` INTEGER  NOT NULL,
+        `culture` VARCHAR(7)  NOT NULL,
+        PRIMARY KEY (`id`,`culture`),
+        CONSTRAINT `relation_i18n_FK_1`
+                FOREIGN KEY (`id`)
+                REFERENCES `relation` (`id`)
+                ON DELETE CASCADE
+)Engine=InnoDB;
+
+sql;
+    QubitPdo::modify($sql);
+
+    // Drop unneeded tables
+    foreach (array(
+      'historical_event',
+      'map',
+      'map_i18n',
+      'place',
+      'place_i18n',
+      'place_map_relation',
+      'rights',
+      'rights_i18n',
+      'rights_actor_relation',
+      'rights_term_relation',
+      'system_event') as $item)
+    {
+      QubitMigrate::dropTable($item);
+    }
+
+    // Drop updated_at and created_at columns
+    foreach (array(
+      'note',
+      'other_name',
+      'property',
+      'status',
+      'taxonomy'
+      ) as $item)
+    {
+      // Copy column updated_at and drop it
+      $sql  = "UPDATE object, $item";
+      $sql .= " SET object.updated_at = $item.updated_at";
+      $sql .= " WHERE object.id = $item.id";
+      QubitPdo::modify($sql);
+      QubitMigrate::dropColumn($item, 'updated_at');
+
+      // Copy column created_at and drop it
+      $sql  = "UPDATE object, $item";
+      $sql .= " SET object.created_at = $item.created_at";
+      $sql .= " WHERE object.id = $item.id";
+      QubitPdo::modify($sql);
+      QubitMigrate::dropColumn($item, 'created_at');
+    }
+
+    // Add table keymap
+    $sql = <<<sql
+
+CREATE TABLE `keymap`
+(
+        `source_id` INTEGER,
+        `target_id` INTEGER,
+        `source_name` TEXT,
+        `target_name` TEXT,
+        `id` INTEGER  NOT NULL AUTO_INCREMENT,
+        `serial_number` INTEGER default 0 NOT NULL,
+        PRIMARY KEY (`id`)
+)Engine=InnoDB;
+
+sql;
+
+    // Add rights and rights_i18n tables
+    $sql = <<<sql
+
+CREATE TABLE `rights`
+(
+        `id` INTEGER  NOT NULL,
+        `start_date` DATE,
+        `end_date` DATE,
+        `restriction` TINYINT default 1,
+        `basis_id` INTEGER,
+        `act_id` INTEGER,
+        `rights_holder_id` INTEGER,
+        `copyright_status_id` INTEGER,
+        `copyright_status_date` DATE,
+        `copyright_jurisdiction` VARCHAR(255),
+        `statute_determination_date` DATE,
+        `source_culture` VARCHAR(7)  NOT NULL,
+        PRIMARY KEY (`id`),
+        CONSTRAINT `rights_FK_1`
+                FOREIGN KEY (`id`)
+                REFERENCES `object` (`id`)
+                ON DELETE CASCADE,
+        INDEX `rights_FI_2` (`basis_id`),
+        CONSTRAINT `rights_FK_2`
+                FOREIGN KEY (`basis_id`)
+                REFERENCES `term` (`id`)
+                ON DELETE SET NULL,
+        INDEX `rights_FI_3` (`act_id`),
+        CONSTRAINT `rights_FK_3`
+                FOREIGN KEY (`act_id`)
+                REFERENCES `term` (`id`)
+                ON DELETE SET NULL,
+        INDEX `rights_FI_4` (`rights_holder_id`),
+        CONSTRAINT `rights_FK_4`
+                FOREIGN KEY (`rights_holder_id`)
+                REFERENCES `actor` (`id`)
+                ON DELETE SET NULL,
+        INDEX `rights_FI_5` (`copyright_status_id`),
+        CONSTRAINT `rights_FK_5`
+                FOREIGN KEY (`copyright_status_id`)
+                REFERENCES `term` (`id`)
+                ON DELETE SET NULL
+)Engine=InnoDB;
+
+CREATE TABLE `rights_i18n`
+(
+        `rights_note` TEXT,
+        `copyright_note` TEXT,
+        `license_identifier` TEXT,
+        `license_terms` TEXT,
+        `license_note` TEXT,
+        `statute_jurisdiction` TEXT,
+        `statute_citation` TEXT,
+        `statute_note` TEXT,
+        `id` INTEGER  NOT NULL,
+        `culture` VARCHAR(7)  NOT NULL,
+        PRIMARY KEY (`id`,`culture`),
+        CONSTRAINT `rights_i18n_FK_1`
+                FOREIGN KEY (`id`)
+                REFERENCES `rights` (`id`)
+                ON DELETE CASCADE
+)Engine=InnoDB;
+
+sql;
+    QubitPdo::modify($sql);
+
+    // Add rights_holder table
+    $sql = <<<sql
+
+CREATE TABLE `rights_holder`
+(
+        `id` INTEGER  NOT NULL,
+        PRIMARY KEY (`id`),
+        CONSTRAINT `rights_holder_FK_1`
+                FOREIGN KEY (`id`)
+                REFERENCES `actor` (`id`)
+                ON DELETE CASCADE
+)Engine=InnoDB;
+
+sql;
+    QubitPdo::modify($sql);
+
+    // Add qtAccessionPlugin SQL
+    $sql = <<<sql
+
+SET FOREIGN_KEY_CHECKS = 0;
+
+CREATE TABLE `accession`
+(
+  `id` INTEGER  NOT NULL,
+  `acquisition_type_id` INTEGER,
+  `date` DATE,
+  `identifier` VARCHAR(255),
+  `processing_priority_id` INTEGER,
+  `processing_status_id` INTEGER,
+  `resource_type_id` INTEGER,
+  `created_at` DATETIME  NOT NULL,
+  `updated_at` DATETIME  NOT NULL,
+  `source_culture` VARCHAR(7)  NOT NULL,
+  PRIMARY KEY (`id`),
+  UNIQUE KEY `accession_U_1` (`identifier`),
+  CONSTRAINT `accession_FK_1`
+    FOREIGN KEY (`id`)
+    REFERENCES `object` (`id`)
+    ON DELETE CASCADE,
+  INDEX `accession_FI_2` (`acquisition_type_id`),
+  CONSTRAINT `accession_FK_2`
+    FOREIGN KEY (`acquisition_type_id`)
+    REFERENCES `term` (`id`)
+    ON DELETE SET NULL,
+  INDEX `accession_FI_3` (`processing_priority_id`),
+  CONSTRAINT `accession_FK_3`
+    FOREIGN KEY (`processing_priority_id`)
+    REFERENCES `term` (`id`)
+    ON DELETE SET NULL,
+  INDEX `accession_FI_4` (`processing_status_id`),
+  CONSTRAINT `accession_FK_4`
+    FOREIGN KEY (`processing_status_id`)
+    REFERENCES `term` (`id`)
+    ON DELETE SET NULL,
+  INDEX `accession_FI_5` (`resource_type_id`),
+  CONSTRAINT `accession_FK_5`
+    FOREIGN KEY (`resource_type_id`)
+    REFERENCES `term` (`id`)
+    ON DELETE SET NULL
+)Engine=InnoDB;
+
+CREATE TABLE `accession_i18n`
+(
+  `appraisal` TEXT,
+  `archival_history` TEXT,
+  `location_information` TEXT,
+  `physical_characteristics` TEXT,
+  `processing_notes` TEXT,
+  `received_extent_units` TEXT,
+  `scope_and_content` TEXT,
+  `source_of_acquisition` TEXT,
+  `title` VARCHAR(255),
+  `id` INTEGER  NOT NULL,
+  `culture` VARCHAR(7)  NOT NULL,
+  PRIMARY KEY (`id`,`culture`),
+  CONSTRAINT `accession_i18n_FK_1`
+    FOREIGN KEY (`id`)
+    REFERENCES `accession` (`id`)
+    ON DELETE CASCADE
+)Engine=InnoDB;
+
+CREATE TABLE `deaccession`
+(
+  `id` INTEGER  NOT NULL,
+  `accession_id` INTEGER,
+  `date` DATE,
+  `identifier` VARCHAR(255),
+  `scope_id` INTEGER,
+  `created_at` DATETIME  NOT NULL,
+  `updated_at` DATETIME  NOT NULL,
+  `source_culture` VARCHAR(7)  NOT NULL,
+  PRIMARY KEY (`id`),
+  CONSTRAINT `deaccession_FK_1`
+    FOREIGN KEY (`id`)
+    REFERENCES `object` (`id`)
+    ON DELETE CASCADE,
+  INDEX `deaccession_FI_2` (`accession_id`),
+  CONSTRAINT `deaccession_FK_2`
+    FOREIGN KEY (`accession_id`)
+    REFERENCES `accession` (`id`)
+    ON DELETE CASCADE,
+  INDEX `deaccession_FI_3` (`scope_id`),
+  CONSTRAINT `deaccession_FK_3`
+    FOREIGN KEY (`scope_id`)
+    REFERENCES `term` (`id`)
+    ON DELETE SET NULL
+)Engine=InnoDB;
+
+CREATE TABLE `deaccession_i18n`
+(
+  `description` TEXT,
+  `extent` TEXT,
+  `reason` TEXT,
+  `id` INTEGER  NOT NULL,
+  `culture` VARCHAR(7)  NOT NULL,
+  PRIMARY KEY (`id`,`culture`),
+  CONSTRAINT `deaccession_i18n_FK_1`
+    FOREIGN KEY (`id`)
+    REFERENCES `deaccession` (`id`)
+    ON DELETE CASCADE
+)Engine=InnoDB;
+
+CREATE TABLE `donor`
+(
+  `id` INTEGER  NOT NULL,
+  PRIMARY KEY (`id`),
+  CONSTRAINT `donor_FK_1`
+    FOREIGN KEY (`id`)
+    REFERENCES `actor` (`id`)
+    ON DELETE CASCADE
+)Engine=InnoDB;
+
+SET FOREIGN_KEY_CHECKS = 1;
+
+sql;
+    QubitPdo::modify($sql);
+  }
 }

-- 
You received this message because you are subscribed to the Google Groups 
"Qubit Toolkit Commits" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/qubit-commits?hl=en.

Reply via email to