Author: david
Date: 2008-12-03 16:52:55 -0800 (Wed, 03 Dec 2008)
New Revision: 1657

Added:
   trunk/qubit/lib/task/migrate/
   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:
Check in migrate task - work in progress.

Added: trunk/qubit/lib/task/migrate/MigrateTask.class.php
===================================================================
--- trunk/qubit/lib/task/migrate/MigrateTask.class.php                          
(rev 0)
+++ trunk/qubit/lib/task/migrate/MigrateTask.class.php  2008-12-04 00:52:55 UTC 
(rev 1657)
@@ -0,0 +1,120 @@
+<?php
+
+/*
+ * This file is part of the symfony package.
+ * (c) 2004-2007 Fabien Potencier <[EMAIL PROTECTED]>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+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
+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(
+      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())
+    {
+      /**
+       * 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());
+
+      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']));
+
+      // Determine current version of the application (according to settings)
+      $initialVersion = $this->getDataVersion($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();
+        }
+      }
+
+      // 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';
+
+      $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)
+      {
+        if ($setting['name'] == 'version')
+        {
+          $currentVersion = preg_replace('/^(\w+ )?\w+ (\d\.\d\.\d)(-\w+)?/', 
'$2', $setting['value']['en']);
+          break;
+        }
+      }
+
+      return $currentVersion;
+    }
+
+    protected static function isValidMigrationPath($startVersion)
+    {
+      if (!in_array($startVersion, self::$migrationMilestones))
+      {
+
+        return false;
+      }
+
+      return true;
+    }
+}
\ No newline at end of file


Property changes on: trunk/qubit/lib/task/migrate/MigrateTask.class.php
___________________________________________________________________
Added: svn:keywords
   + Author Id Revision
Added: svn:eol-style
   + native

Added: trunk/qubit/lib/task/migrate/QubitMigrate103to104.class.php
===================================================================
--- trunk/qubit/lib/task/migrate/QubitMigrate103to104.class.php                 
        (rev 0)
+++ trunk/qubit/lib/task/migrate/QubitMigrate103to104.class.php 2008-12-04 
00:52:55 UTC (rev 1657)
@@ -0,0 +1,193 @@
+<?php
+/*
+ * This file is part of the Qubit Toolkit.
+ * Copyright (C) 2006-2008 Peter Van Garderen <[EMAIL PROTECTED]>
+ *
+ * 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 from 1.0.3 to 1.0.4
+ *
+ * @package    qubit
+ * @subpackage migration
+ * @version    svn: $Id$
+ * @author     David Juhasz <[EMAIL PROTECTED]>
+ */
+class QubitMigrate103to104 extends QubitMigrateData
+{
+  public static function execute($data)
+  {
+    $data = self::alterData($data);
+    self::alterSchema();
+
+    return $data;
+  }
+
+  protected static function alterData($data)
+  {
+    // Move QubitTaxonomy to front of the line
+    if (key($data) != 'QubitTaxonomy')
+    {
+      $taxonomy = array('QubitTaxonomy' => $data['QubitTaxonomy']);
+      $data['QubitTaxonomy'] = null;
+      $data = array_merge_recursive($taxonomy, $data);
+    }
+
+    // Move QubitProperty::value column to QubitPropertyI18n::value
+    foreach ($data['QubitProperty'] as $key => $property)
+    {
+      $data['QubitProperty'][$key]['value'] = array('en' => 
$property['value']);
+    }
+
+    // Add new QubitTaxonomy objects
+    $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(
+      '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(
+      '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',
+      'source_culture' => 'en',
+      'name' => array('en' => 'Author')
+    );
+    $data['QubitTerm']['QubitTerm_10b'] = array(
+      'taxonomy_id' => 'QubitTaxonomy_9',
+      'source_culture' => 'en',
+      'name' => array('en' => 'Editor')
+    );
+    $data['QubitTerm']['QubitTerm_10c'] = array(
+      'taxonomy_id' => 'QubitTaxonomy_9',
+      'source_culture' => 'en',
+      'name' => array('en' => 'Translator')
+    );
+    $data['QubitTerm']['QubitTerm_10d'] = array(
+      'taxonomy_id' => 'QubitTaxonomy_9',
+      'source_culture' => 'en',
+      'name' => array('en' => 'Compiler')
+    );
+    $data['QubitTerm']['QubitTerm_10e'] = array(
+      'taxonomy_id' => 'QubitTaxonomy_9',
+      'source_culture' => 'en',
+      'name' => array('en' => 'Distributor')
+    );
+    $data['QubitTerm']['QubitTerm_10f'] = array(
+      'taxonomy_id' => 'QubitTaxonomy_9',
+      'source_culture' => 'en',
+      'name' => array('en' => 'Broadcaster')
+    );
+    $data['QubitTerm']['QubitTerm_10g'] = array(
+      'taxonomy_id' => 'QubitTaxonomy_9',
+      'source_culture' => 'en',
+      'name' => array('en' => 'Manufacturer')
+    );
+    $data['QubitTerm']['QubitTerm_17a'] = array(
+      'taxonomy_id' => 'QubitTaxonomy_10',
+      'source_culture' => 'en',
+      'name' => array('en' => 'Writing')
+    );
+    $data['QubitTerm']['QubitTerm_17b'] = array(
+      'taxonomy_id' => 'QubitTaxonomy_10',
+      'source_culture' => 'en',
+      'name' => array('en' => 'Editing')
+    );
+    $data['QubitTerm']['QubitTerm_17c'] = array(
+      'taxonomy_id' => 'QubitTaxonomy_10',
+      'source_culture' => 'en',
+      'name' => array('en' => 'Translation')
+    );
+    $data['QubitTerm']['QubitTerm_17d'] = array(
+      'taxonomy_id' => 'QubitTaxonomy_10',
+      'source_culture' => 'en',
+      'name' => array('en' => 'Compilation')
+    );
+    $data['QubitTerm']['QubitTerm_17e'] = array(
+      'taxonomy_id' => 'QubitTaxonomy_10',
+      'source_culture' => 'en',
+      'name' => array('en' => 'Distribution')
+    );
+    $data['QubitTerm']['QubitTerm_17f'] = array(
+      'taxonomy_id' => 'QubitTaxonomy_10',
+      'source_culture' => 'en',
+      'name' => array('en' => 'Broadcasting')
+    );
+    $data['QubitTerm']['QubitTerm_17g'] = array(
+      'taxonomy_id' => 'QubitTaxonomy_10',
+      'source_culture' => 'en',
+      'name' => array('en' => 'Manufacturing')
+    );
+
+    // 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']);
+      }
+    }
+
+    // Update version number
+    foreach ($data['QubitSetting'] as $key => $setting)
+    {
+      if ($setting['name'] == 'version')
+      {
+        $data['QubitSetting'][$key]['value'] = array('en' => '1.0.4');
+        break;
+      }
+    }
+
+    foreach ($data['QubitStaticPage'] as $key => $page)
+    {
+      if ($page['permalink'] == 'homepage' || $page['permalink'] == 'about')
+      {
+        array_walk($data['QubitStaticPage'][$key]['content'], 
create_function('&$x','$x=str_replace(\'1.0.3\', \'1.0.4\', $x);'));
+      }
+    }
+
+    ob_start();
+    var_dump($data);
+    $dataString = ob_get_contents();
+    ob_end_clean();
+
+    if (!($fh = fopen('./updatedDataArray.txt', 'w')))
+    {
+      die('Couldn\'t open file');
+    }
+    fwrite($fh, $dataString);
+    fclose($fh);
+
+    return $data;
+  }
+
+  protected static function alterSchema()
+  {
+    $sql = 'alter table ';
+  }
+}


Property changes on: trunk/qubit/lib/task/migrate/QubitMigrate103to104.class.php
___________________________________________________________________
Added: svn:keywords
   + Author Id Revision
Added: svn:eol-style
   + native

Added: trunk/qubit/lib/task/migrate/QubitMigrateData.class.php
===================================================================
--- trunk/qubit/lib/task/migrate/QubitMigrateData.class.php                     
        (rev 0)
+++ trunk/qubit/lib/task/migrate/QubitMigrateData.class.php     2008-12-04 
00:52:55 UTC (rev 1657)
@@ -0,0 +1,56 @@
+<?php
+/*
+ * This file is part of the Qubit Toolkit.
+ * Copyright (C) 2006-2008 Peter Van Garderen <[EMAIL PROTECTED]>
+ *
+ * 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.
+ */
+
+/**
+ * Abstract class defining inteface for upgrading the Qubit data model
+ *
+ * @package    qubit
+ * @subpackage migration
+ * @version    svn: $Id$
+ * @author     David Juhasz <[EMAIL PROTECTED]>
+ */
+class QubitMigrateData
+{
+  protected $data = null;
+
+  public function __construct($data)
+  {
+    $this->setData($data);
+  }
+
+  public function setData($data)
+  {
+    $this->data = $data;
+
+    return $this;
+  }
+
+  public function getData()
+  {
+    return $this->data;
+  }
+
+  public function migrate103to104()
+  {
+    $this->data = QubitMigrate103to104::execute($this->data);
+
+    return $this;
+  }
+}
\ No newline at end of file


Property changes on: trunk/qubit/lib/task/migrate/QubitMigrateData.class.php
___________________________________________________________________
Added: svn:keywords
   + Author Id Revision
Added: svn:eol-style
   + native


--~--~---------~--~----~------------~-------~--~----~
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