Author: david
Date: 2008-12-10 18:11:33 -0800 (Wed, 10 Dec 2008)
New Revision: 1672
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:
More work on migrate task.
Modified: trunk/qubit/lib/task/migrate/MigrateTask.class.php
===================================================================
--- trunk/qubit/lib/task/migrate/MigrateTask.class.php 2008-12-11 00:38:07 UTC
(rev 1671)
+++ trunk/qubit/lib/task/migrate/MigrateTask.class.php 2008-12-11 02:11:33 UTC
(rev 1672)
@@ -19,7 +19,7 @@
*/
/**
- * Upgrade qubit data model
+ * Migrate qubit data model
*
* @package qubit
* @subpackage migration
@@ -40,18 +40,16 @@
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->name = 'migrate';
+ $this->briefDescription = 'Migrate 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:
+The [propel:migrate|INFO] task modifies the given YAML dump file with changes
to the data structure and fixtures in subsequent versions of the application:
- [./symfony propel:upgrade qubit qubit_data_1.0.3.yml|INFO]
+ [./symfony propel:migrate 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'),
+ new sfCommandArgument('datafile', sfCommandArgument::REQUIRED, 'The yaml
data file containing the current site data')
));
}
@@ -60,15 +58,6 @@
*/
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.');
@@ -95,19 +84,25 @@
}
// TODO: write new data.yml file
+ $this->dumpDataFromArray($migrator->getData());
+
// TODO: move sampleData.yml? (svn will be sad :( )
// TODO: run propel:build-all-load?
}
- protected function dumpData($arguments, $options)
+ protected function dumpDataFromArray($data)
{
- // load Propel configuration before Phing
- $databaseManager = new sfDatabaseManager($this->configuration);
- require_once
sfConfig::get('sf_symfony_lib_dir').'/plugins/sfPropelPlugin/lib/propel/sfPropelAutoload.php';
+ $yamlFileName = 'migrated_data_v104.yml';
+ $dir = sfConfig::get('sf_data_dir').DIRECTORY_SEPARATOR.'fixtures';
+ $filename = $dir.DIRECTORY_SEPARATOR.$yamlFileName;
- $dump = new sfPropelDumpDataTask($this->dispatcher, $this->formatter);
- $dump->setCommandApplication($this->commandApplication);
- $dump->run($arguments, $options);
+ $yamlDumper = new sfYamlDumper();
+ $fileContents = sfYaml::dump($data, 3);
+
+ // Remove single quotes from <?php statements
+ $fileContents = preg_replace("/'(\<\?php echo .+ \?\>)'/", '$1',
$fileContents);
+
+ file_put_contents($filename, $fileContents);
}
protected function getDataVersion($data)
Modified: trunk/qubit/lib/task/migrate/QubitMigrate103to104.class.php
===================================================================
--- trunk/qubit/lib/task/migrate/QubitMigrate103to104.class.php 2008-12-11
00:38:07 UTC (rev 1671)
+++ trunk/qubit/lib/task/migrate/QubitMigrate103to104.class.php 2008-12-11
02:11:33 UTC (rev 1672)
@@ -21,7 +21,7 @@
/**
* Upgrade qubit data model from 1.0.3 to 1.0.4
*
- * @package qubi
+ * @package qubit
* @subpackage migration
* @version svn: $Id$
* @author David Juhasz <[EMAIL PROTECTED]
@@ -39,7 +39,7 @@
/**
* Do migration of data from 1.0.3 to 1.0.4
*
- * @return array modified d
+ * @return array modified data
*/
public function execute()
{
@@ -49,9 +49,9 @@
}
/**
- * Getter for migration d
+ * Getter for migration data
*
- * @return array arrayized yaml d
+ * @return array arrayized yaml data
*/
public function getData()
{
@@ -73,9 +73,9 @@
}
/**
- * Controller for calling methods to alter d
+ * Controller for calling methods to alter data
*
- * @return QubitMigrate103to104 this objec
+ * @return QubitMigrate103to104 this object
*/
protected function alterData()
{
@@ -83,7 +83,7 @@
if (key($this->data) != 'QubitTaxonomy')
{
$taxonomy = array('QubitTaxonomy' => $this->data['QubitTaxonomy']);
- $this->data['QubitTaxonomy'] = null;
+ unset($this->data['QubitTaxonomy']);
$this->data = array_merge_recursive($taxonomy, $this->data);
}
@@ -112,9 +112,9 @@
}
/**
- * Alter QubitEvent d
+ * Alter QubitEvent data
*
- * @return QubitMigrate103to104 this objec
+ * @return QubitMigrate103to104 this object
*/
protected function alterQubitEvents()
{
@@ -151,9 +151,9 @@
}
/**
- * Alter QubitNotes d
+ * Alter QubitNotes data
*
- * @return QubitMigrate103to104 this objec
+ * @return QubitMigrate103to104 this object
*/
protected function alterQubitNotes()
{
@@ -191,7 +191,6 @@
'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',
@@ -214,14 +213,6 @@
'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',
@@ -303,9 +294,9 @@
}
/**
- * Alter QubitStaticPage d
+ * Alter QubitStaticPage data
*
- * @return QubitMigrate103to104 this objec
+ * @return QubitMigrate103to104 this object
*/
protected function alterQubitStaticPages()
{
@@ -322,9 +313,9 @@
}
/**
- * Alter QubitSetting d
+ * Alter QubitSetting data
*
- * @return QubitMigrate103to104 this objec
+ * @return QubitMigrate103to104 this object
*/
protected function alterQubitSettings()
{
@@ -355,7 +346,7 @@
}
// Add new Default Template Qubit Settings (insert in place of previous
- // default template d
+ // default template data
$defaultTemplates['QubitSetting_default_template_informationobject'] =
array(
'name' => 'informationobject',
'scope' => 'default_template',
@@ -428,9 +419,9 @@
}
/**
- * Alter QubitTaxonomy d
+ * Alter QubitTaxonomy data
*
- * @return QubitMigrate103to104 this objec
+ * @return QubitMigrate103to104 this object
*/
protected function alterQubitTaxonomy()
{
@@ -463,21 +454,34 @@
}
/**
- * Alter QubitTerm d
+ * Alter QubitTerm data
*
- * @return QubitMigrate103to104 this objec
+ * @return QubitMigrate103to104 this object
*/
protected function alterQubitTerms()
{
- // Swap Event Type: Existence -> Subjec
+ // Swap Event Type: Existence -> Subject
if ($existenceKey = $this->getRowKey('QubitTerm', 'id', '<?php echo
QubitTerm::EXISTENCE_ID."\n" ?>'))
{
-
+ $this->data['QubitTerm'][$existenceKey]['id'] = '<?php echo
QubitTerm::SUBJECT_ID."\n" ?>';
+ $this->data['QubitTerm'][$existenceKey]['name'] = array(
+ 'en'=>'Subject', 'fr' => 'Sujet', 'nl' => 'Onderwerp', 'pt' =>
'Assunto');
}
// Get taxonomy event type key
$taxonomyEventTypeKey = $this->getRowKey('QubitTaxonomy', 'id', '<?php
echo QubitTaxonomy::EVENT_TYPE_ID."\n" ?>');
+ // Add QubitTerm:accumulation after QubitTerm:collection
+ $collectionKey = $this->getRowKey('QubitTerm', 'id', '<?php echo
QubitTerm::COLLECTION_ID."\n" ?>');
+ $collectionIndex =
QubitMigrateData::getArrayKeyIndex($this->data['QubitTerm'], $collectionKey);
+ $newQubitTerms['QubitTerm_accumulation'] = array(
+ 'taxonomy_id' => $taxonomyEventTypeKey,
+ 'id' => '<?php echo QubitTerm::ACCUMULATION_ID."\n" ?>',
+ 'source_culture' => 'en',
+ 'name' => array('en' => 'Accumulation')
+ );
+ QubitMigrateData::array_insert($this->data['QubitTerm'],
($collectionIndex+1), $newQubitTerms);
+
// Event Types
$this->data['QubitTerm']['QubitTerm_writing'] = array(
'taxonomy_id' => $taxonomyEventTypeKey,
@@ -516,111 +520,121 @@
);
// Material Types
- $this->data['QubitTerm']['material_type_architectural_drawing'] = array(
+ $this->data['QubitTerm']['QubitTerm_material_type_architectural_drawing']
= array(
'taxonomy_id' => 'QubitTaxonomy_MaterialType',
'class_name' => 'QubitTerm',
'source_culture' => 'en',
'name' => array('en' => 'Architectural drawing')
);
- $this->data['QubitTerm']['material_type_cartographic_material'] = array(
+ $this->data['QubitTerm']['QubitTerm_material_type_cartographic_material']
= array(
'taxonomy_id' => 'QubitTaxonomy_MaterialType',
'class_name' => 'QubitTerm',
'source_culture' => 'en',
'name' => array('en' => 'Cartographic material')
);
- $this->data['QubitTerm']['material_type_graphic_material'] = array(
+ $this->data['QubitTerm']['QubitTerm_material_type_graphic_material'] =
array(
'taxonomy_id' => 'QubitTaxonomy_MaterialType',
'class_name' => 'QubitTerm',
'source_culture' => 'en',
'name' => array('en' => 'Graphic material')
);
- $this->data['QubitTerm']['material_type_moving_images'] = array(
+ $this->data['QubitTerm']['QubitTerm_material_type_moving_images'] = array(
'taxonomy_id' => 'QubitTaxonomy_MaterialType',
'class_name' => 'QubitTerm',
'source_culture' => 'en',
'name' => array('en' => 'Moving images')
);
- $this->data['QubitTerm']['material_type_multiple_media'] = array(
+ $this->data['QubitTerm']['QubitTerm_material_type_multiple_media'] = array(
'taxonomy_id' => 'QubitTaxonomy_MaterialType',
'class_name' => 'QubitTerm',
'source_culture' => 'en',
'name' => array('en' => 'Multiple media')
);
- $this->data['QubitTerm']['material_type_object'] = array(
+ $this->data['QubitTerm']['QubitTerm_material_type_object'] = array(
'taxonomy_id' => 'QubitTaxonomy_MaterialType',
'class_name' => 'QubitTerm',
'source_culture' => 'en',
'name' => array('en' => 'Object')
);
- $this->data['QubitTerm']['material_type_philatelic_record'] = array(
+ $this->data['QubitTerm']['QubitTerm_material_type_philatelic_record'] =
array(
'taxonomy_id' => 'QubitTaxonomy_MaterialType',
'class_name' => 'QubitTerm',
'source_culture' => 'en',
'name' => array('en' => 'Philatelic record')
);
- $this->data['QubitTerm']['material_type_sound_recording'] = array(
+ $this->data['QubitTerm']['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(
+ $this->data['QubitTerm']['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(
+ $this->data['QubitTerm']['QubitTerm_material_type_textual_record'] = array(
'taxonomy_id' => 'QubitTaxonomy_MaterialType',
'class_name' => 'QubitTerm',
'source_culture' => 'en',
'name' => array('en' => 'Textual record')
);
+ // Display Note
+ $taxonomyNoteTypeKey = $this->getRowKey('QubitTaxonomy', 'id', '<?php echo
QubitTaxonomy::NOTE_TYPE_ID."\n" ?>');
+ $this->data['QubitTerm']['QubitTerm_display_note'] = array(
+ 'taxonomy_id' => $taxonomyNoteTypeKey,
+ 'id' => '<?php echo QubitTerm::DISPLAY_NOTE_ID."\n" ?>',
+ 'class_name' => 'QubitTerm',
+ 'source_culture' => 'en',
+ 'name' => array('en' => 'Display note')
+ );
+
// RAD Note Types
- $this->data['QubitTerm']['rad_notes_edition'] = array(
+ $this->data['QubitTerm']['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(
+ $this->data['QubitTerm']['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(
+ $this->data['QubitTerm']['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(
+ $this->data['QubitTerm']['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(
+ $this->data['QubitTerm']['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(
+ $this->data['QubitTerm']['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(
+ $this->data['QubitTerm']['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(
+ $this->data['QubitTerm']['QubitTerm_rad_notes_general_note'] = array(
'taxonomy_id' => 'QubitTaxonomy_Rad_Note',
'class_name' => 'QubitTerm',
'source_culture' => 'en',
@@ -628,37 +642,37 @@
);
// RAD Title Notes
- $this->data['QubitTerm']['rad_title_variations_in_title'] = array(
+ $this->data['QubitTerm']['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(
+ $this->data['QubitTerm']['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(
+ $this->data['QubitTerm']['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(
+ $this->data['QubitTerm']['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(
+
$this->data['QubitTerm']['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(
+
$this->data['QubitTerm']['QubitTerm_rad_title_attributions_and_conjectures'] =
array(
'taxonomy_id' => 'QubitTaxonomy_Rad_Title_Note',
'class_name' => 'QubitTerm',
'source_culture' => 'en',
@@ -671,13 +685,19 @@
{
foreach ($this->data['QubitTerm'] as $key => $columns)
{
- if ($columns['taxonomy_id'] == $taxonomyActorRoleKey)
+ if (isset($columns['taxonomy_id']) && $columns['taxonomy_id'] ==
$taxonomyActorRoleKey)
{
unset($this->data['QubitTerm'][$key]);
}
}
}
+ // Remove SUBJECT_ACCESS_POINT_ID term
+ if ($subjectAccessPointKey = $this->getRowKey('QubitTerm', 'id', '<?php
echo QubitTerm::SUBJECT_ACCESS_POINT_ID."\n" ?>'))
+ {
+ unset($this->data['QubitTerm'][$subjectAccessPointKey]);
+ }
+
return $this;
}
Modified: trunk/qubit/lib/task/migrate/QubitMigrateData.class.php
===================================================================
--- trunk/qubit/lib/task/migrate/QubitMigrateData.class.php 2008-12-11
00:38:07 UTC (rev 1671)
+++ trunk/qubit/lib/task/migrate/QubitMigrateData.class.php 2008-12-11
02:11:33 UTC (rev 1672)
@@ -58,7 +58,7 @@
/**
* 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
@@ -80,7 +80,7 @@
/**
* 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)
*
@@ -93,4 +93,26 @@
$first_array = array_splice ($array, 0, $position);
$array = array_merge ($first_array, $insert_array, $array);
}
+
+ /**
+ * Get the index for a given key of an associative array
+ *
+ * @param array $arr array to search
+ * @param string $findKey key to search for
+ * @return mixed integer on success, false (bool) if key does not exist
+ */
+ public static function getArrayKeyIndex($arr, $findKey)
+ {
+ $index = 0;
+ foreach ($arr as $key => $value)
+ {
+ if ($key == $findKey)
+ {
+ return $index;
+ }
+ $index++;
+ }
+
+ return false;
+ }
}
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---