Author: david
Date: 2008-12-08 12:40:38 -0800 (Mon, 08 Dec 2008)
New Revision: 1665

Modified:
   trunk/qubit/lib/task/migrate/MigrateTask.class.php
   trunk/qubit/lib/task/migrate/QubitMigrate103to104.class.php
   trunk/qubit/lib/task/migrate/QubitMigrateData.class.php
Log:
Working on QubitMigration for 1.0.3 -> 1.0.4.

Modified: trunk/qubit/lib/task/migrate/MigrateTask.class.php
===================================================================
--- trunk/qubit/lib/task/migrate/MigrateTask.class.php  2008-12-08 08:12:01 UTC 
(rev 1664)
+++ trunk/qubit/lib/task/migrate/MigrateTask.class.php  2008-12-08 20:40:38 UTC 
(rev 1665)
@@ -1,120 +1,138 @@
 <?php
-
 /*
- * This file is part of the symfony package.
- * (c) 2004-2007 Fabien Potencier <[EMAIL PROTECTED]>
+ * This file is part of the Qubit Toolkit.
+ * Copyright (C) 2006-2008 Peter Van Garderen <[EMAIL PROTECTED]>
  *
- * For the full copyright and license information, please view the LICENSE
- * file that was distributed with this source code.
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the Free
+ * Software Foundation; either version 2 of the License, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; if not, write to the Free Software Foundation, Inc., 51
+ * Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
  */
 
+/**
+ * Upgrade qubit data model
+ *
+ * @package    qubit
+ * @subpackage migration
+ * @version    svn: $Id$
+ * @author     David Juhasz <[EMAIL PROTECTED]>
+ */
 class UpgradeTask extends sfBaseTask
 {
   // Qubit Generic Icon list
   private static $migrationMilestones = array(
     '1.0.3',
     '1.0.4'
-    );
+  );
 
-    /**
-     * @see sfBaseTask
-     */
-    protected function configure()
-    {
-      $this->namespace = 'propel';
-      $this->name = 'upgrade';
-      $this->briefDescription = 'Upgrade the database schema and existing data 
for compatibility with a newer version of Qubit.';
-      $this->detailedDescription = <<<EOF
+  /**
+   * @see sfBaseTask
+   */
+  protected function configure()
+  {
+    $this->namespace = 'propel';
+    $this->name = 'upgrade';
+    $this->briefDescription = 'Upgrade the database schema and existing data 
for compatibility with a newer version of Qubit.';
+    $this->detailedDescription = <<<EOF
 The [propel:upgrade|INFO] task does the necessary data schema and structure 
for 
 compatiblilty with a new version of Qubit:
 
   [./symfony propel:upgrade qubit qubit_data_1.0.3.yml|INFO]
 EOF;
 
-      $this->addArguments(array(
+    $this->addArguments(array(
       new sfCommandArgument('application', sfCommandArgument::REQUIRED, 'The 
application name'),
       new sfCommandArgument('datafile', sfCommandArgument::REQUIRED, 'The yaml 
data file containing the current site data'),
-      ));
-    }
+    ));
+  }
 
+  /**
+   * @see sfBaseTask
+   */
+  protected function execute($arguments = array(), $options = array())
+  {
     /**
-     * @see sfBaseTask
+     * NOTE: Can't dump OLD data file using current codebase e.g. once upgraded
+     * to version 1.0.4, the data dump command no longer works for 1.0.3 data 
:(
      */
-    protected function execute($arguments = array(), $options = array())
+    // Dump existing data to a yaml file
+    //$dumpFile = 
sfConfig::get('sf_data_dir').'/backup/'.$arguments['application'].date('Ymd').'.yml';
+    //$this->logSection('propel', 'Backup existing data to '.$dumpFile);
+    //$this->dumpData(array('application' => $arguments['application'], 
'target' => $dumpFile), array());
+
+    if (!is_readable($arguments['datafile']))
     {
-      /**
-       * NOTE: Can't dump OLD data file using current codebase e.g. once 
upgraded
-       * to version 1.0.4, the data dump command no longer works for 1.0.3 
data :(
-       */
-      // Dump existing data to a yaml file
-      //$dumpFile = 
sfConfig::get('sf_data_dir').'/backup/'.$arguments['application'].date('Ymd').'.yml';
-      //$this->logSection('propel', 'Backup existing data to '.$dumpFile);
-      //$this->dumpData(array('application' => $arguments['application'], 
'target' => $dumpFile), array());
+      $this->log('The file '.$arguments['datafile'].' is not readable.');
+      die();
+    }
 
-      if (!is_readable($arguments['datafile']))
-      {
-        $this->log('The file '.$arguments['datafile'].' is not readable.');
-        die();
-      }
+    // load yml dumpfile into an array ($data)
+    $yamlParser = new sfYamlParser;
+    $data = $yamlParser->parse(file_get_contents($arguments['datafile']));
 
-      // load yml dumpfile into an array ($data)
-      $yamlParser = new sfYamlParser;
-      $data = $yamlParser->parse(file_get_contents($arguments['datafile']));
+    // Determine current version of the application (according to settings)
+    $initialVersion = $this->getDataVersion($data);
 
-      // Determine current version of the application (according to settings)
-      $initialVersion = $this->getDataVersion($data);
+    $migrator = new QubitMigrateData($data);
 
-      $migrator = new QubitMigrateData($data);
-
-      // Incrementally call the upgrade task for each intervening version from
-      // current version to final version
-      if (self::isValidMigrationPath($initialVersion))
-      {
-        switch ($initialVersion){
-          case '1.0.3':
-            $migrator->migrate103to104();
-        }
+    // Incrementally call the upgrade task for each intervening version from
+    // current version to final version
+    if (self::isValidMigrationPath($initialVersion))
+    {
+      switch ($initialVersion){
+        case '1.0.3':
+          $migrator->migrate103to104();
       }
-
-      // TODO: write new data.yml file
-      // TODO: move sampleData.yml? (svn will be sad :( )
-      // TODO: run propel:build-all-load?
     }
 
-    protected function dumpData($arguments, $options)
-    {
-      // load Propel configuration before Phing
-      $databaseManager = new sfDatabaseManager($this->configuration);
-      require_once 
sfConfig::get('sf_symfony_lib_dir').'/plugins/sfPropelPlugin/lib/propel/sfPropelAutoload.php';
+    // TODO: write new data.yml file
+    // TODO: move sampleData.yml? (svn will be sad :( )
+    // TODO: run propel:build-all-load?
+  }
 
-      $dump = new sfPropelDumpDataTask($this->dispatcher, $this->formatter);
-      $dump->setCommandApplication($this->commandApplication);
-      $dump->run($arguments, $options);
-    }
+  protected function dumpData($arguments, $options)
+  {
+    // load Propel configuration before Phing
+    $databaseManager = new sfDatabaseManager($this->configuration);
+    require_once 
sfConfig::get('sf_symfony_lib_dir').'/plugins/sfPropelPlugin/lib/propel/sfPropelAutoload.php';
 
-    protected function getDataVersion($data)
+    $dump = new sfPropelDumpDataTask($this->dispatcher, $this->formatter);
+    $dump->setCommandApplication($this->commandApplication);
+    $dump->run($arguments, $options);
+  }
+
+  protected function getDataVersion($data)
+  {
+    $currentVersion = null;
+    foreach ($data['QubitSetting'] as $setting)
     {
-      $currentVersion = null;
-      foreach ($data['QubitSetting'] as $setting)
+      if ($setting['name'] == 'version')
       {
-        if ($setting['name'] == 'version')
-        {
-          $currentVersion = preg_replace('/^(\w+ )?\w+ (\d\.\d\.\d)(-\w+)?/', 
'$2', $setting['value']['en']);
-          break;
-        }
+        $currentVersion = preg_replace('/^(\w+ )?\w+ (\d\.\d\.\d)(-\w+)?/', 
'$2', $setting['value']['en']);
+        break;
       }
-
-      return $currentVersion;
     }
 
-    protected static function isValidMigrationPath($startVersion)
+    return $currentVersion;
+  }
+
+  protected static function isValidMigrationPath($startVersion)
+  {
+    if (!in_array($startVersion, self::$migrationMilestones))
     {
-      if (!in_array($startVersion, self::$migrationMilestones))
-      {
 
-        return false;
-      }
+      return false;
+    }
 
-      return true;
-    }
+    return true;
+  }
 }
\ No newline at end of file

Modified: trunk/qubit/lib/task/migrate/QubitMigrate103to104.class.php
===================================================================
--- trunk/qubit/lib/task/migrate/QubitMigrate103to104.class.php 2008-12-08 
08:12:01 UTC (rev 1664)
+++ trunk/qubit/lib/task/migrate/QubitMigrate103to104.class.php 2008-12-08 
20:40:38 UTC (rev 1665)
@@ -1,9 +1,9 @@
 <?php
 /*
  * This file is part of the Qubit Toolkit.
- * Copyright (C) 2006-2008 Peter Van Garderen <[EMAIL PROTECTED]>
+ * Copyright (C) 2006-2008 Peter Van Garderen <[EMAIL PROTECTED]
  *
- * This program is free software; you can redistribute it and/or modify it
+ * This program is free software; you can redistribute it and/or modify i
  * under the terms of the GNU General Public License as published by the Free
  * Software Foundation; either version 2 of the License, or (at your option)
  * any later version.
@@ -21,173 +21,678 @@
 /**
  * Upgrade qubit data model from 1.0.3 to 1.0.4
  *
- * @package    qubit
+ * @package    qubi
  * @subpackage migration
  * @version    svn: $Id$
- * @author     David Juhasz <[EMAIL PROTECTED]>
+ * @author     David Juhasz <[EMAIL PROTECTED]
  */
-class QubitMigrate103to104 extends QubitMigrateData
+class QubitMigrate103to104
 {
-  public static function execute($data)
+  private $taxonomyActorRoleKey;
+  private $data;
+
+  public function __construct($data)
   {
-    $data = self::alterData($data);
-    self::alterSchema();
+    $this->data = $data;
+  }
 
-    return $data;
+  /**
+   * Do migration of data from 1.0.3 to 1.0.4
+   *
+   * @return array modified d
+   */
+  public function execute()
+  {
+    $this->alterData();
+
+    return $this->getData();
   }
 
-  protected static function alterData($data)
+  /**
+   * Getter for migration d
+   *
+   * @return array arrayized yaml d
+   */
+  public function getData()
   {
+    return $this->data;
+  }
+
+  /**
+   * Wrapper for QubitMigrateData::findRowKeyForColumnValue() method.
+   *
+   * @param string $className
+   * @param string $searchColumn
+   * @param string $searchKey
+   * @return string key for matched row
+   */
+  protected function getRowKey($className, $searchColumn, $searchKey)
+  {
+    return QubitMigrateData::findRowKeyForColumnValue(
+      $this->data[$className], $searchColumn, $searchKey);
+  }
+
+  /**
+   * Controller for calling methods to alter d
+   *
+   * @return QubitMigrate103to104 this objec
+   */
+  protected function alterData()
+  {
     // Move QubitTaxonomy to front of the line
-    if (key($data) != 'QubitTaxonomy')
+    if (key($this->data) != 'QubitTaxonomy')
     {
-      $taxonomy = array('QubitTaxonomy' => $data['QubitTaxonomy']);
-      $data['QubitTaxonomy'] = null;
-      $data = array_merge_recursive($taxonomy, $data);
+      $taxonomy = array('QubitTaxonomy' => $this->data['QubitTaxonomy']);
+      $this->data['QubitTaxonomy'] = null;
+      $this->data = array_merge_recursive($taxonomy, $this->data);
     }
 
-    // Move QubitProperty::value column to QubitPropertyI18n::value
-    foreach ($data['QubitProperty'] as $key => $property)
+    // Alter qubit objects
+    $this->alterQubitEvents();
+    $this->alterQubitNotes();
+    $this->alterQubitProperties();
+    $this->alterQubitStaticPages();
+    $this->alterQubitSettings();
+    $this->alterQubitTaxonomy();
+    $this->alterQubitTerms();
+
+    ob_start();
+    var_dump($this->data);
+    $dataString = ob_get_contents();
+    ob_end_clean();
+
+    if (!($fh = fopen('./updatedDataArray.txt', 'w')))
     {
-      $data['QubitProperty'][$key]['value'] = array('en' => 
$property['value']);
+      die('Couldn\'t open file');
     }
+    fwrite($fh, $dataString);
+    fclose($fh);
 
+    return $this;
+  }
+
+  /**
+   * Alter QubitEvent d
+   *
+   * @return QubitMigrate103to104 this objec
+   */
+  protected function alterQubitEvents()
+  {
+    // re-map data QubitEvent::description -> QubitEvent::date_display
+    foreach ($this->data['QubitEvent'] as $key => $event)
+    {
+      if (isset($this->data['QubitEvent'][$key]['description']))
+      {
+        $this->data['QubitEvent'][$key]['date_display'] = 
$this->data['QubitEvent'][$key]['description'];
+        unset($this->data['QubitEvent'][$key]['description']);
+      }
+    }
+
+    // Add actor to TeleLearning Network creation even
+    $teleLearningFondsKey = $this->getRowKey('QubitInformationObject', 
'title', array('en' => 'TeleLearning Network fonds'));
+    $teleLearningActorKey = $this->getRowKey('QubitActor', 
'authorized_form_of_name', array('en' => 'TeleLearning Network Inc'));
+    $creationEventTermKey = $this->getRowKey('QubitTerm', 'id', '<?php echo 
QubitTerm::CREATION_ID."\n" ?>');
+
+    if ($teleLearningFondsKey && $teleLearningActorKey && 
$creationEventTermKey)
+    {
+      foreach ($this->data['QubitEvent'] as $key => $columns)
+      {
+        if (isset($columns['information_object_id']) && 
isset($columns['type_id'])
+          && $columns['information_object_id'] == $teleLearningFondsKey
+          && $columns['type_id'] == $creationEventTermKey)
+        {
+          $this->data['QubitEvent'][$key]['actor_id'] = $teleLearningActorKey;
+          break;
+        }
+      }
+    }
+
+    return $this;
+  }
+
+  /**
+   * Alter QubitNotes d
+   *
+   * @return QubitMigrate103to104 this objec
+   */
+  protected function alterQubitNotes()
+  {
+    // Add new Qubit Notes
+    $this->data['QubitNote']['QubitNote_accumulator'] = array(
+      'object_id' => 'QubitTerm_Accumulation',
+      'type_id' => 'QubitTerm_display_note',
+      'user_id' => 'QubitUser_113',
+      'scope' => 'QubitTerm',
+      'source_culture' => 'en',
+      'content' => array('en' => 'Accumulator')
+    );
+    $this->data['QubitNote']['QubitNote_creator'] = array(
+      'object_id' => 'QubitTerm_11',
+      'type_id' => 'QubitTerm_display_note',
+      'user_id' => 'QubitUser_113',
+      'scope' => 'QubitTerm',
+      'source_culture' => 'en',
+      'content' => array('en' => 'Creator', 'es' => 'Produtor', 'fr' => 
'Producteur', 'nl' => 'Vervaardiger', 'pt' => 'Produtor')
+    );
+    $this->data['QubitNote']['QubitNote_subject'] = array(
+      'object_id' => 'QubitTerm_12',
+      'type_id' => 'QubitTerm_display_note',
+      'user_id' => 'QubitUser_113',
+      'scope' => 'QubitTerm',
+      'source_culture' => 'en',
+      'content' => array('en' => 'Subject', 'fr' => 'Sujet', 'nl' => 
'Onderwerp', 'pt' => 'Assunto')
+    );
+    $this->data['QubitNote']['QubitNote_custodian'] = array(
+      'object_id' => 'QubitTerm_13',
+      'type_id' => 'QubitTerm_display_note',
+      'user_id' => 'QubitUser_113',
+      'scope' => 'QubitTerm',
+      'source_culture' => 'en',
+      'content' => array('en' => 'Custodian', 'es' => 'Custodiador', 'fr' => 
'Détenteur', 'nl' => 'Beheerder', 'pt' => 'Custodiador')
+    );
+    $this->data['QubitNote']['QubitNote_publisher'] = array(
+      'object_id' => 'QubitTerm_14',
+      'type_id' => 'QubitTerm_display_note',
+      'user_id' => 'QubitUser_113',
+      'scope' => 'QubitTerm',
+      'source_culture' => 'en',
+      'content' => array('en' => 'Publisher', 'es' => 'Publicador', 'fr' => 
'Éditeur', 'nl' => 'Uitgever', 'pt' => 'Publicador')
+    );
+    $this->data['QubitNote']['QubitNote_contributor'] = array(
+      'object_id' => 'QubitTerm_15',
+      'type_id' => 'QubitTerm_display_note',
+      'user_id' => 'QubitUser_113',
+      'scope' => 'QubitTerm',
+      'source_culture' => 'en',
+      'content' => array('en' => 'Contributor', 'es' => 'Colaborador', 'fr' => 
'Collaborateur', 'nl' => 'Contribuant', 'pt' => 'Colaborador')
+    );
+    $this->data['QubitNote']['QubitNote_collector'] = array(
+      'object_id' => 'QubitTerm_17',
+      'type_id' => 'QubitTerm_display_note',
+      'user_id' => 'QubitUser_113',
+      'scope' => 'QubitTerm',
+      'source_culture' => 'en',
+      'content' => array('en' => 'Collector', 'fr' => 'Collectionneur', 'nl' 
=> 'Verzamelaar', 'pt' => 'Coletor')
+    );
+    $this->data['QubitNote']['QubitNote_accumulator'] = array(
+      'object_id' => 'QubitTerm_Accumulation',
+      'type_id' => 'QubitTerm_display_note',
+      'user_id' => 'QubitUser_113',
+      'scope' => 'QubitTerm',
+      'source_culture' => 'en',
+      'content' => array('en' => 'Accumulator')
+    );
+    $this->data['QubitNote']['QubitNote_author'] = array(
+      'object_id' => 'QubitTerm_17a',
+      'type_id' => 'QubitTerm_display_note',
+      'user_id' => 'QubitUser_113',
+      'scope' => 'QubitTerm',
+      'source_culture' => 'en',
+      'content' => array('en' => 'Author')
+    );
+    $this->data['QubitNote']['QubitNote_editor'] = array(
+      'object_id' => 'QubitTerm_17b',
+      'type_id' => 'QubitTerm_display_note',
+      'user_id' => 'QubitUser_113',
+      'scope' => 'QubitTerm',
+      'source_culture' => 'en',
+      'content' => array('en' => 'Editor')
+    );
+    $this->data['QubitNote']['QubitNote_translator'] = array(
+      'object_id' => 'QubitTerm_17c',
+      'type_id' => 'QubitTerm_display_note',
+      'user_id' => 'QubitUser_113',
+      'scope' => 'QubitTerm',
+      'source_culture' => 'en',
+      'content' => array('en' => 'Translator')
+    );
+    $this->data['QubitNote']['QubitNote_compiler'] = array(
+      'object_id' => 'QubitTerm_17d',
+      'type_id' => 'QubitTerm_display_note',
+      'user_id' => 'QubitUser_113',
+      'scope' => 'QubitTerm',
+      'source_culture' => 'en',
+      'content' => array('en' => 'Compiler')
+    );
+    $this->data['QubitNote']['QubitNote_distributor'] = array(
+      'object_id' => 'QubitTerm_17e',
+      'type_id' => 'QubitTerm_display_note',
+      'user_id' => 'QubitUser_113',
+      'scope' => 'QubitTerm',
+      'source_culture' => 'en',
+      'content' => array('en' => 'Distributor')
+    );
+    $this->data['QubitNote']['QubitNote_broadcaster'] = array(
+      'object_id' => 'QubitTerm_17f',
+      'type_id' => 'QubitTerm_display_note',
+      'user_id' => 'QubitUser_113',
+      'scope' => 'QubitTerm',
+      'source_culture' => 'en',
+      'content' => array('en' => 'Broadcaster')
+    );
+    $this->data['QubitNote']['QubitNote_manufacturer'] = array(
+      'object_id' => 'QubitTerm_17g',
+      'type_id' => 'QubitTerm_display_note',
+      'user_id' => 'QubitUser_113',
+      'scope' => 'QubitTerm',
+      'source_culture' => 'en',
+      'content' => array('en' => 'Manufacturer')
+    );
+
+    return $this;
+  }
+
+  /**
+   * Alter QubitProperty d
+   *
+   * @return QubitMigrate103to104 this objec
+   */
+  protected function alterQubitProperties()
+  {
+    // re-map QubitProperty 'value' column to i18n table
+    foreach ($this->data['QubitProperty'] as $key => $property)
+    {
+      if (isset($property['value']))
+      {
+        $this->data['QubitProperty'][$key]['source_culture'] = 'en';
+        $this->data['QubitProperty'][$key]['value'] = array('en' => 
$property['value']);
+      }
+    }
+
+    return $this;
+  }
+
+  /**
+   * Alter QubitStaticPage d
+   *
+   * @return QubitMigrate103to104 this objec
+   */
+  protected function alterQubitStaticPages()
+  {
+    // Update version number
+    foreach ($this->data['QubitStaticPage'] as $key => $page)
+    {
+      if ($page['permalink'] == 'homepage' || $page['permalink'] == 'about')
+      {
+        array_walk($this->data['QubitStaticPage'][$key]['content'], 
create_function('&$x','$x=str_replace(\'1.0.3\', \'1.0.4\', $x);'));
+      }
+    }
+
+    return $this;
+  }
+
+  /**
+   * Alter QubitSetting d
+   *
+   * @return QubitMigrate103to104 this objec
+   */
+  protected function alterQubitSettings()
+  {
+    // Remove old QubitSettings for default templates
+    $i = 0;
+    foreach ($this->data['QubitSetting'] as $key => $setting)
+    {
+      switch ($setting['name'])
+      {
+        case 'informationobject_edit':
+        case 'informationobject_show':
+        case 'informationobject_list':
+        case 'actor_edit':
+        case 'actor_show':
+        case 'actor_list':
+        case 'repository_edit':
+        case 'repository_show':
+        case 'repository_list':
+          if (!isset($defaultTemplateIndex))
+          {
+            $defaultTemplateIndex = $i;
+          }
+          unset($this->data['QubitSetting'][$key]);
+          break;
+      }
+
+      $i++;
+    }
+
+    // Add new Default Template Qubit Settings (insert in place of previous
+    // default template d
+    $defaultTemplates['QubitSetting_default_template_informationobject'] = 
array(
+      'name' => 'informationobject',
+      'scope' => 'default_template',
+      'editable' => '1',
+      'deleteable' => '0',
+      'source_culture' => 'en',
+      'value' => array('en' => 'isad')
+    );
+    $defaultTemplates['QubitSetting_default_template_actor'] = array(
+      'name' => 'actor',
+      'scope' => 'default_template',
+      'editable' => '1',
+      'deleteable' => '0',
+      'source_culture' => 'en',
+      'value' => array('en' => 'isaar')
+    );
+    $defaultTemplates['QubitSetting_default_template_repository'] = array(
+      'name' => 'repository',
+      'scope' => 'default_template',
+      'editable' => '1',
+      'deleteable' => '0',
+      'source_culture' => 'en',
+      'value' => array('en' => 'isdiah')
+    );
+    QubitMigrateData::array_insert($this->data['QubitSetting'], 
$defaultTemplateIndex, $defaultTemplates);
+
+    $this->data['QubitSetting']['QubitSetting_multi_repository'] = array(
+      'name' => 'multi_repository',
+      'editable' => '1',
+      'deleteable' => '0',
+      'source_culture' => 'en',
+      'value' => array('en' => '1'),
+    );
+    $this->data['QubitSetting']['QubitSetting_site_title'] = array(
+      'name' => 'site_title',
+      'scope' => 'site_information',
+      'editable' => '1',
+      'deleteable' => '0',
+      'source_culture' => 'en',
+      'value' => array('en' => ''),
+    );
+    $this->data['QubitSetting']['QubitSetting_site_description'] = array(
+      'name' => 'site_description',
+      'scope' => 'site_information',
+      'editable' => '1',
+      'deleteable' => '0',
+      'source_culture' => 'en',
+      'value' => array('en' => ''),
+    );
+    $this->data['QubitSetting']['QubitSetting_material_type'] = array(
+      'name' => 'materialtype',
+      'scope' => 'ui_label',
+      'editable' => '1',
+      'deleteable' => '0',
+      'source_culture' => 'en',
+      'value' => array('en' => 'material type'),
+    );
+
+    // Update version number
+    foreach ($this->data['QubitSetting'] as $key => $setting)
+    {
+      if ($setting['name'] == 'version')
+      {
+        $this->data['QubitSetting'][$key]['value'] = array('en' => '1.0.4');
+        break;
+      }
+    }
+
+    return $this;
+  }
+
+  /**
+   * Alter QubitTaxonomy d
+   *
+   * @return QubitMigrate103to104 this objec
+   */
+  protected function alterQubitTaxonomy()
+  {
     // Add new QubitTaxonomy objects
-    $data['QubitTaxonomy']['QubitTaxonomy_MaterialType'] = array(
+    $this->data['QubitTaxonomy']['QubitTaxonomy_MaterialType'] = array(
       'source_culture' => 'en',
       'id' => '<?php echo QubitTaxonomy::MATERIAL_TYPE_ID."\n" ?>',
       'name' => array('en' => 'Material Type')
     );
-    $data['QubitTaxonomy']['QubitTaxonomy_Rad_Note'] = array(
+    $this->data['QubitTaxonomy']['QubitTaxonomy_Rad_Note'] = array(
       'source_culture' => 'en',
       'id' => '<?php echo QubitTaxonomy::RAD_NOTE_ID."\n" ?>',
       'name' => array('en' => 'RAD Note'),
       'note' => array('en' => 'Note types that occur specifically within the 
Canadian Council on Archives\' Rules for Archival Description (RAD)')
     );
-    $data['QubitTaxonomy']['QubitTaxonomy_Rad_Title_Note'] = array(
+    $this->data['QubitTaxonomy']['QubitTaxonomy_Rad_Title_Note'] = array(
       'source_culture' => 'en',
       'id' => '<?php echo QubitTaxonomy::RAD_TITLE_NOTE_ID."\n" ?>',
       'name' => array('en' => 'RAD Title Note'),
       'note' => array('en' => 'Title note types that occur specifically within 
the Canadian Council on Archives\' Rules for Archival Description (RAD)')
     );
 
-    // Add new QubitTerm objects
-    $data['QubitTerm']['QubitTerm_10a'] = array(
-      'taxonomy_id' => 'QubitTaxonomy_9',
+    // Remove actor role Taxonomy
+    if ($taxonomyActorRoleKey = $this->getTaxonomyActorRoleKey())
+    {
+      unset($this->data['QubitTaxonomy'][$taxonomyActorRoleKey]);
+    }
+
+    return $this;
+  }
+
+  /**
+   * Alter QubitTerm d
+   *
+   * @return QubitMigrate103to104 this objec
+   */
+  protected function alterQubitTerms()
+  {
+    // Swap Event Type: Existence -> Subjec
+    if ($existenceKey = $this->getRowKey('QubitTerm', 'id', '<?php echo 
QubitTerm::EXISTENCE_ID."\n" ?>'))
+    {
+
+    }
+
+    // Get taxonomy event type key
+    $taxonomyEventTypeKey = $this->getRowKey('QubitTaxonomy', 'id', '<?php 
echo QubitTaxonomy::EVENT_TYPE_ID."\n" ?>');
+
+    // Event Types
+    $this->data['QubitTerm']['QubitTerm_writing'] = array(
+      'taxonomy_id' => $taxonomyEventTypeKey,
       'source_culture' => 'en',
-      'name' => array('en' => 'Author')
+      'name' => array('en' => 'Writing')
     );
-    $data['QubitTerm']['QubitTerm_10b'] = array(
-      'taxonomy_id' => 'QubitTaxonomy_9',
+    $this->data['QubitTerm']['QubitTerm_editing'] = array(
+      'taxonomy_id' => $taxonomyEventTypeKey,
       'source_culture' => 'en',
-      'name' => array('en' => 'Editor')
+      'name' => array('en' => 'Editing')
     );
-    $data['QubitTerm']['QubitTerm_10c'] = array(
-      'taxonomy_id' => 'QubitTaxonomy_9',
+    $this->data['QubitTerm']['QubitTerm_translation'] = array(
+      'taxonomy_id' => $taxonomyEventTypeKey,
       'source_culture' => 'en',
-      'name' => array('en' => 'Translator')
+      'name' => array('en' => 'Translation')
     );
-    $data['QubitTerm']['QubitTerm_10d'] = array(
-      'taxonomy_id' => 'QubitTaxonomy_9',
+    $this->data['QubitTerm']['QubitTerm_compilation'] = array(
+      'taxonomy_id' => $taxonomyEventTypeKey,
       'source_culture' => 'en',
-      'name' => array('en' => 'Compiler')
+      'name' => array('en' => 'Compilation')
     );
-    $data['QubitTerm']['QubitTerm_10e'] = array(
-      'taxonomy_id' => 'QubitTaxonomy_9',
+    $this->data['QubitTerm']['QubitTerm_distribution'] = array(
+      'taxonomy_id' => $taxonomyEventTypeKey,
       'source_culture' => 'en',
-      'name' => array('en' => 'Distributor')
+      'name' => array('en' => 'Distribution')
     );
-    $data['QubitTerm']['QubitTerm_10f'] = array(
-      'taxonomy_id' => 'QubitTaxonomy_9',
+    $this->data['QubitTerm']['QubitTerm_broadcasting'] = array(
+      'taxonomy_id' => $taxonomyEventTypeKey,
       'source_culture' => 'en',
-      'name' => array('en' => 'Broadcaster')
+      'name' => array('en' => 'Broadcasting')
     );
-    $data['QubitTerm']['QubitTerm_10g'] = array(
-      'taxonomy_id' => 'QubitTaxonomy_9',
+    $this->data['QubitTerm']['QubitTerm_manufacturing'] = array(
+      'taxonomy_id' => $taxonomyEventTypeKey,
       'source_culture' => 'en',
-      'name' => array('en' => 'Manufacturer')
+      'name' => array('en' => 'Manufacturing')
     );
-    $data['QubitTerm']['QubitTerm_17a'] = array(
-      'taxonomy_id' => 'QubitTaxonomy_10',
+
+    // Material Types
+    $this->data['QubitTerm']['material_type_architectural_drawing'] = array(
+      'taxonomy_id' => 'QubitTaxonomy_MaterialType',
+      'class_name' => 'QubitTerm',
       'source_culture' => 'en',
-      'name' => array('en' => 'Writing')
+      'name' => array('en' => 'Architectural drawing')
     );
-    $data['QubitTerm']['QubitTerm_17b'] = array(
-      'taxonomy_id' => 'QubitTaxonomy_10',
+    $this->data['QubitTerm']['material_type_cartographic_material'] = array(
+      'taxonomy_id' => 'QubitTaxonomy_MaterialType',
+      'class_name' => 'QubitTerm',
       'source_culture' => 'en',
-      'name' => array('en' => 'Editing')
+      'name' => array('en' => 'Cartographic material')
     );
-    $data['QubitTerm']['QubitTerm_17c'] = array(
-      'taxonomy_id' => 'QubitTaxonomy_10',
+    $this->data['QubitTerm']['material_type_graphic_material'] = array(
+      'taxonomy_id' => 'QubitTaxonomy_MaterialType',
+      'class_name' => 'QubitTerm',
       'source_culture' => 'en',
-      'name' => array('en' => 'Translation')
+      'name' => array('en' => 'Graphic material')
     );
-    $data['QubitTerm']['QubitTerm_17d'] = array(
-      'taxonomy_id' => 'QubitTaxonomy_10',
+    $this->data['QubitTerm']['material_type_moving_images'] = array(
+      'taxonomy_id' => 'QubitTaxonomy_MaterialType',
+      'class_name' => 'QubitTerm',
       'source_culture' => 'en',
-      'name' => array('en' => 'Compilation')
+      'name' => array('en' => 'Moving images')
     );
-    $data['QubitTerm']['QubitTerm_17e'] = array(
-      'taxonomy_id' => 'QubitTaxonomy_10',
+    $this->data['QubitTerm']['material_type_multiple_media'] = array(
+      'taxonomy_id' => 'QubitTaxonomy_MaterialType',
+      'class_name' => 'QubitTerm',
       'source_culture' => 'en',
-      'name' => array('en' => 'Distribution')
+      'name' => array('en' => 'Multiple media')
     );
-    $data['QubitTerm']['QubitTerm_17f'] = array(
-      'taxonomy_id' => 'QubitTaxonomy_10',
+    $this->data['QubitTerm']['material_type_object'] = array(
+      'taxonomy_id' => 'QubitTaxonomy_MaterialType',
+      'class_name' => 'QubitTerm',
       'source_culture' => 'en',
-      'name' => array('en' => 'Broadcasting')
+      'name' => array('en' => 'Object')
     );
-    $data['QubitTerm']['QubitTerm_17g'] = array(
-      'taxonomy_id' => 'QubitTaxonomy_10',
+    $this->data['QubitTerm']['material_type_philatelic_record'] = array(
+      'taxonomy_id' => 'QubitTaxonomy_MaterialType',
+      'class_name' => 'QubitTerm',
       'source_culture' => 'en',
-      'name' => array('en' => 'Manufacturing')
+      'name' => array('en' => 'Philatelic record')
     );
+    $this->data['QubitTerm']['material_type_sound_recording'] = array(
+      'taxonomy_id' => 'QubitTaxonomy_MaterialType',
+      'class_name' => 'QubitTerm',
+      'source_culture' => 'en',
+      'name' => array('en' => 'Sound recording')
+    );
+    $this->data['QubitTerm']['material_type_technical_drawing'] = array(
+      'taxonomy_id' => 'QubitTaxonomy_MaterialType',
+      'class_name' => 'QubitTerm',
+      'source_culture' => 'en',
+      'name' => array('en' => 'Technical drawing')
+    );
+    $this->data['QubitTerm']['material_type_textual_record'] = array(
+      'taxonomy_id' => 'QubitTaxonomy_MaterialType',
+      'class_name' => 'QubitTerm',
+      'source_culture' => 'en',
+      'name' => array('en' => 'Textual record')
+    );
 
-    // re-map data QubitEvent::description -> QubitEvent::date_display
-    foreach ($data['QubitEvent'] as $key => $event)
-    {
-      if (isset($data['QubitEvent'][$key]['description']))
-      {
-        $data['QubitEvent'][$key]['date_display'] = 
$data['QubitEvent'][$key]['description'];
-        unset($data['QubitEvent'][$key]['description']);
-      }
-    }
+    // RAD Note Types
+    $this->data['QubitTerm']['rad_notes_edition'] = array(
+      'taxonomy_id' => 'QubitTaxonomy_Rad_Note',
+      'class_name' => 'QubitTerm',
+      'source_culture' => 'en',
+      'name' => array('en' => 'Edition')
+    );
+    $this->data['QubitTerm']['rad_notes_physical_description'] = array(
+      'taxonomy_id' => 'QubitTaxonomy_Rad_Note',
+      'class_name' => 'QubitTerm',
+      'source_culture' => 'en',
+      'name' => array('en' => 'Physical description')
+    );
+    $this->data['QubitTerm']['rad_notes_conservation'] = array(
+      'taxonomy_id' => 'QubitTaxonomy_Rad_Note',
+      'class_name' => 'QubitTerm',
+      'source_culture' => 'en',
+      'name' => array('en' => 'Conservation')
+    );
+    $this->data['QubitTerm']['rad_notes_accompanying_material'] = array(
+      'taxonomy_id' => 'QubitTaxonomy_Rad_Note',
+      'class_name' => 'QubitTerm',
+      'source_culture' => 'en',
+      'name' => array('en' => 'Accompanying material')
+    );
+    $this->data['QubitTerm']['rad_notes_publishers_series'] = array(
+      'taxonomy_id' => 'QubitTaxonomy_Rad_Note',
+      'class_name' => 'QubitTerm',
+      'source_culture' => 'en',
+      'name' => array('en' => 'Publisher\'s series')
+    );
+    $this->data['QubitTerm']['rad_notes_alpha_numeric_designations'] = array(
+      'taxonomy_id' => 'QubitTaxonomy_Rad_Note',
+      'class_name' => 'QubitTerm',
+      'source_culture' => 'en',
+      'name' => array('en' => 'Alpha-numeric designations')
+    );
+    $this->data['QubitTerm']['rad_notes_rights'] = array(
+      'taxonomy_id' => 'QubitTaxonomy_Rad_Note',
+      'class_name' => 'QubitTerm',
+      'source_culture' => 'en',
+      'name' => array('en' => 'Rights')
+    );
+    $this->data['QubitTerm']['rad_notes_general_note'] = array(
+      'taxonomy_id' => 'QubitTaxonomy_Rad_Note',
+      'class_name' => 'QubitTerm',
+      'source_culture' => 'en',
+      'name' => array('en' => 'General note')
+    );
 
-    // Update version number
-    foreach ($data['QubitSetting'] as $key => $setting)
-    {
-      if ($setting['name'] == 'version')
-      {
-        $data['QubitSetting'][$key]['value'] = array('en' => '1.0.4');
-        break;
-      }
-    }
+    // RAD Title Notes
+    $this->data['QubitTerm']['rad_title_variations_in_title'] = array(
+      'taxonomy_id' => 'QubitTaxonomy_Rad_Title_Note',
+      'class_name' => 'QubitTerm',
+      'source_culture' => 'en',
+      'name' => array('en' => 'Variations in title')
+    );
+    $this->data['QubitTerm']['rad_title_source_of_title_proper'] = array(
+      'taxonomy_id' => 'QubitTaxonomy_Rad_Title_Note',
+      'class_name' => 'QubitTerm',
+      'source_culture' => 'en',
+      'name' => array('en' => 'Source of title proper')
+    );
+    $this->data['QubitTerm']['rad_title_parallel_titles_etc'] = array(
+      'taxonomy_id' => 'QubitTaxonomy_Rad_Title_Note',
+      'class_name' => 'QubitTerm',
+      'source_culture' => 'en',
+      'name' => array('en' => 'Parallel titles and other title information')
+    );
+    $this->data['QubitTerm']['rad_title_continuation_of_title'] = array(
+      'taxonomy_id' => 'QubitTaxonomy_Rad_Title_Note',
+      'class_name' => 'QubitTerm',
+      'source_culture' => 'en',
+      'name' => array('en' => 'Continuation of title')
+    );
+    $this->data['QubitTerm']['rad_title_statements_of_responsibility'] = array(
+      'taxonomy_id' => 'QubitTaxonomy_Rad_Title_Note',
+      'class_name' => 'QubitTerm',
+      'source_culture' => 'en',
+      'name' => array('en' => 'Statements of responsibility')
+    );
+    $this->data['QubitTerm']['rad_title_attributions_and_conjectures'] = array(
+      'taxonomy_id' => 'QubitTaxonomy_Rad_Title_Note',
+      'class_name' => 'QubitTerm',
+      'source_culture' => 'en',
+      'name' => array('en' => 'Attributions and conjectures')
+    );
 
-    foreach ($data['QubitStaticPage'] as $key => $page)
+    // Remove Actor Role Taxonomy Terms
+    $taxonomyActorRoleKey = $this->getTaxonomyActorRoleKey();
+    if ($taxonomyActorRoleKey)
     {
-      if ($page['permalink'] == 'homepage' || $page['permalink'] == 'about')
+      foreach ($this->data['QubitTerm'] as $key => $columns)
       {
-        array_walk($data['QubitStaticPage'][$key]['content'], 
create_function('&$x','$x=str_replace(\'1.0.3\', \'1.0.4\', $x);'));
+        if ($columns['taxonomy_id'] == $taxonomyActorRoleKey)
+        {
+          unset($this->data['QubitTerm'][$key]);
+        }
       }
     }
 
-    ob_start();
-    var_dump($data);
-    $dataString = ob_get_contents();
-    ob_end_clean();
+    return $this;
+  }
 
-    if (!($fh = fopen('./updatedDataArray.txt', 'w')))
+  /**
+   * Get Taxonomy Actor Role key - used to delete the taxonomy and it's terms
+   *
+   * @return string key for the Taxonomy in $this->data array
+   */
+  protected function getTaxonomyActorRoleKey()
+  {
+    if (!isset($this->taxonomyActorRoleKey))
     {
-      die('Couldn\'t open file');
+      $this->taxonomyActorRoleKey = $this->getRowKey('QubitTaxonomy', 'id', 
'<?php echo QubitTaxonomy::ACTOR_ROLE_ID."\n" ?>');
     }
-    fwrite($fh, $dataString);
-    fclose($fh);
 
-    return $data;
+    return $this->taxonomyActorRoleKey;
   }
-
-  protected static function alterSchema()
-  {
-    $sql = 'alter table ';
-  }
-}
+} // Close class QubitMigrate103to104

Modified: trunk/qubit/lib/task/migrate/QubitMigrateData.class.php
===================================================================
--- trunk/qubit/lib/task/migrate/QubitMigrateData.class.php     2008-12-08 
08:12:01 UTC (rev 1664)
+++ trunk/qubit/lib/task/migrate/QubitMigrateData.class.php     2008-12-08 
20:40:38 UTC (rev 1665)
@@ -49,8 +49,48 @@
 
   public function migrate103to104()
   {
-    $this->data = QubitMigrate103to104::execute($this->data);
+    $migrator = new QubitMigrate103to104($this->data);
+    $this->data = $migrator->execute();
 
     return $this;
   }
-}
\ No newline at end of file
+
+  /**
+   * Loop through row searching for $searchColumn value = $searchValue.
+   * Return row key for first matched object.
+   * 
+   * @param string $searchRow row array to search
+   * @param string $searchColumn Name of column to check for $searchValue
+   * @param mixed  $searchValue Value to find - can be string or array
+   * @return array row key
+   */
+  public static function findRowKeyForColumnValue($searchRow, $searchColumn, 
$searchValue)
+  {
+    foreach ($searchRow as $key => $columns)
+    {
+      if (isset($columns[$searchColumn]) && $columns[$searchColumn] == 
$searchValue)
+      {
+
+        return $key;
+      }
+    }
+
+    return false;
+  }
+
+  /**
+   * Splice two associative arrays.
+   * 
+   * From http://ca3.php.net/manual/en/function.array-splice.php
+   * @author weikard at gmx dot de (15-Sep-2005 08:53)
+   *
+   * @param array $array Primary array
+   * @param integer $position insert index
+   * @param array $insert_array spliced array
+   */
+  public static function array_insert(&$array, $position, $insert_array)
+  {
+    $first_array = array_splice ($array, 0, $position);
+    $array = array_merge ($first_array, $insert_array, $array);
+  }
+}


--~--~---------~--~----~------------~-------~--~----~
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.ca/group/qubit-commits?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to