Author: david
Date: Fri May 4 16:01:16 2012
New Revision: 11640
Log:
Add code to run upgrader code, and add arUpgrader120 for Release 1.2 upgrades
Added:
trunk/lib/task/migrate/arUpgrader120.class.php
- copied, changed from r11633,
trunk/lib/task/migrate/QubitMigrate120.class.php
Modified:
trunk/lib/task/migrate/arUpgradeSqlTask.class.php
Modified: trunk/lib/task/migrate/arUpgradeSqlTask.class.php
==============================================================================
--- trunk/lib/task/migrate/arUpgradeSqlTask.class.php Fri May 4 15:58:09
2012 (r11639)
+++ trunk/lib/task/migrate/arUpgradeSqlTask.class.php Fri May 4 16:01:16
2012 (r11640)
@@ -119,16 +119,33 @@
return 1;
}
- // TODO Do upgrade
// Find all the upgrade classes in lib/task/migrate
+ $version = $this->initialVersion;
foreach
(sfFinder::type('file')->maxdepth(0)->name('arUpgrader*.class.php')->in(sfConfig::get('sf_lib_dir').'/task/migrate')
as $filename)
{
- $className = ucfirst(str_replace($filename, '.class.php', ''));
- $this->upgraders[constant($className, '::INIT_VERSION')] = $className;
+ $className = preg_replace('/.*(arUpgrader\d+).*/', '$1', $filename);
+ $class = new $className;
+
+ if ($class::INIT_VERSION <= $version)
+ {
+ $this->logSection('upgrade-sql', sprintf('Upgrading from Release %s',
$class::MILESTONE));
+ while ($class->up($version))
+ {
+ $version++;
+ }
+ }
}
- var_dump($this->upgraders);
- $this->logSection('upgrade-sql', sprintf('Upgrading from version %s',
$this->initialVersion));
+ // TODO Upgrade version in database
+
+ if ($this->initialVersion == $version)
+ {
+ $this->logSection('upgrade-sql', sprintf('Already at latest version
(%s), no upgrades done', $version));
+ }
+ else
+ {
+ $this->logSection('upgrade-sql', sprintf('Upgraded to Release %s v%s',
$class::MILESTONE, $version));
+ }
}
protected function parseDsn($dsn)
Copied and modified: trunk/lib/task/migrate/arUpgrader120.class.php (from
r11633, trunk/lib/task/migrate/QubitMigrate120.class.php)
==============================================================================
--- trunk/lib/task/migrate/QubitMigrate120.class.php Fri May 4 00:03:02
2012 (r11633, copy source)
+++ trunk/lib/task/migrate/arUpgrader120.class.php Fri May 4 16:01:16
2012 (r11640)
@@ -18,57 +18,48 @@
*/
/**
- * Upgrade qubit version 1.2 data for version 1.2.1
+ * Upgrade Qubit data from Release 1.2
*
* @package qubit
* @subpackage migration
- * @version svn: $Id: QubitMigrate110.class.php 10379 2011-12-08 21:26:13Z
david $
+ * @version svn: $Id$
*/
-class QubitMigrate120 extends QubitMigrate
+class arUpgrader120
{
const
MILESTONE = '1.2',
- INIT_VERSION = 75,
- FINAL_VERSION = null;
+ INIT_VERSION = 75;
- public function execute()
+ public function up($version)
{
- $this->slugData();
- $this->alterData();
- $this->sortData();
-
- return $this->getData();
- }
-
- /**
- * Controller for calling methods to alter data
- *
- * @return QubitMigrate120 this object
- */
- protected function alterData()
- {
- switch ($this->version)
+ switch($version)
{
case 75:
- $this->addJobSchedulingSettings();
+ // $this->addJobSchedulingSettings();
+ break;
case 76:
- $this->addSwordSettings();
+ //$this->addSwordSettings();
+ break;
case 77:
- $this->addSecuritySettings();
+ //$this->addSecuritySettings();
+ break;
case 78:
- $this->addBrowserSortSettings();
+ //$this->addBrowserSortSettings();
+ break;
case 79:
- $this->addLanguageNoteTerm();
- }
+ //$this->addLanguageNoteTerm();
+ break;
- // Delete "stub" objects
- $this->deleteStubObjects();
+ // Return false if no upgrade available
+ default:
+ return false;
+ }
- return $this;
+ return true;
}
/**
@@ -170,275 +161,4 @@
return $this;
}
-
- /**
- * Slugs are inserted when some resources are inserted, but slugs are dumped
- * separately when data is dumped. So loading slug data will try to insert
- * duplicate slugs. To work around this, turn slugs into resource properties
- * and drop slug data
- */
- protected function slugData()
- {
- if (!isset($this->data['QubitSlug']))
- {
- return $this;
- }
-
- $slug = array();
- foreach ($this->data['QubitSlug'] as $item)
- {
- $slug[$item['object_id']] = $item['slug'];
- }
-
- unset($this->data['QubitSlug']);
-
- foreach ($this->data as $table => $value)
- {
- foreach ($value as $row => $value)
- {
- if (isset ($slug[$row]))
- {
- $this->data[$table][$row]['slug'] = $slug[$row];
- }
- }
- }
-
- return $this;
- }
-
- /**
- * Call all sort methods
- *
- * @return QubitMigrate120 this object
- */
- protected function sortData()
- {
- // Sort objects within classes
- $this->sortQubitInformationObjects();
- $this->sortQubitTerms();
-
- // Sort classes
- $this->sortClasses();
-
- return $this;
- }
-
- /**
- * Sort information objects by lft value so that parent objects are inserted
- * before their children.
- *
- * @return QubitMigrate120 this object
- */
- protected function sortQubitInformationObjects()
- {
- QubitMigrate::sortByLft($this->data['QubitInformationObject']);
-
- return $this;
- }
-
- /**
- * Sort term objects with pre-defined IDs to start of array to prevent
- * pre-emptive assignment by auto-increment
- *
- * @return QubitMigrate120 this object
- */
- protected function sortQubitTerms()
- {
- $qubitTermConstantIds = array(
- 'ROOT_ID',
- //EventType taxonomy
- 'CREATION_ID',
- 'CUSTODY_ID',
- 'PUBLICATION_ID',
- 'CONTRIBUTION_ID',
- 'COLLECTION_ID',
- 'ACCUMULATION_ID',
- //NoteType taxonomy
- 'TITLE_NOTE_ID',
- 'PUBLICATION_NOTE_ID',
- 'SOURCE_NOTE_ID',
- 'SCOPE_NOTE_ID',
- 'DISPLAY_NOTE_ID',
- 'ARCHIVIST_NOTE_ID',
- 'GENERAL_NOTE_ID',
- 'OTHER_DESCRIPTIVE_DATA_ID',
- 'MAINTENANCE_NOTE_ID',
- //CollectionType taxonomy
- 'ARCHIVAL_MATERIAL_ID',
- 'PUBLISHED_MATERIAL_ID',
- 'ARTEFACT_MATERIAL_ID',
- //ActorEntityType taxonomy
- 'CORPORATE_BODY_ID',
- 'PERSON_ID',
- 'FAMILY_ID',
- //OtherNameType taxonomy
- 'FAMILY_NAME_FIRST_NAME_ID',
- //MediaType taxonomy
- 'AUDIO_ID',
- 'IMAGE_ID',
- 'TEXT_ID',
- 'VIDEO_ID',
- 'OTHER_ID',
- //Digital Object Usage taxonomy
- 'MASTER_ID',
- 'REFERENCE_ID',
- 'THUMBNAIL_ID',
- 'COMPOUND_ID',
- //Physical Object Type taxonomy
- 'LOCATION_ID',
- 'CONTAINER_ID',
- 'ARTEFACT_ID',
- //Relation Type taxonomy
- 'HAS_PHYSICAL_OBJECT_ID',
- //Actor name type taxonomy
- 'PARALLEL_FORM_OF_NAME_ID',
- 'OTHER_FORM_OF_NAME_ID',
- //Actor relation type taxonomy
- 'HIERARCHICAL_RELATION_ID',
- 'TEMPORAL_RELATION_ID',
- 'FAMILY_RELATION_ID',
- 'ASSOCIATIVE_RELATION_ID',
- //Relation NOTE type taxonomy
- 'RELATION_NOTE_DESCRIPTION_ID',
- 'RELATION_NOTE_DATE_ID',
- //Term relation taxonomy
- 'ALTERNATIVE_LABEL_ID',
- 'TERM_RELATION_ASSOCIATIVE_ID',
- //Status types taxonomy
- 'STATUS_TYPE_PUBLICATION_ID',
- // Publication status taxonomy
- 'PUBLICATION_STATUS_DRAFT_ID',
- 'PUBLICATION_STATUS_PUBLISHED_ID',
- // Name access point
- 'NAME_ACCESS_POINT_ID',
- // ISDF relation type taxonomy
- 'ISDF_HIERARCHICAL_RELATION_ID',
- 'ISDF_TEMPORAL_RELATION_ID',
- 'ISDF_ASSOCIATIVE_RELATION_ID',
- // ISAAR standardized form name
- 'STANDARDIZED_FORM_OF_NAME_ID',
- 'EXTERNAL_URI_ID',
- // Relation types
- 'ACCESSION_ID',
- 'RIGHT_ID',
- 'DONOR_ID',
- // Rights basis
- 'RIGHT_BASIS_COPYRIGHT_ID',
- 'RIGHT_BASIS_LICENSE_ID',
- 'RIGHT_BASIS_STATUTE_ID',
- 'RIGHT_BASIS_POLICY_ID'
- );
-
- // Restack array with Constant values at top
- $qubitTermArray = $this->data['QubitTerm'];
- foreach ($qubitTermConstantIds as $key => $constantName)
- {
- foreach ($qubitTermArray as $key => $term)
- {
- if (isset($term['id']) && $term['id'] == '<?php echo
QubitTerm::'.$constantName.'."\n" ?>')
- {
- $newTermArray[$key] = $term;
- unset($qubitTermArray[$key]);
- break;
- }
- }
- }
-
- // Sort remainder of array by lft values
- QubitMigrate::sortByLft($qubitTermArray);
-
- // Append remaining (variable id) terms to the end of the new array
- foreach ($qubitTermArray as $key => $term)
- {
- $newTermArray[$key] = $term;
- }
-
- $this->data['QubitTerm'] = $newTermArray;
-
- return $this;
- }
-
- /**
- * Sort ORM classes to avoid foreign key constraint failures on data load
- *
- * @return QubitMigrate120 this object
- */
- protected function sortClasses()
- {
- $ormSortOrder = array(
- 'QubitTaxonomy',
- 'QubitTerm',
- 'QubitActor',
- 'QubitRepository',
- 'QubitInformationObject',
- 'QubitDigitalObject',
- 'QubitEvent',
- 'QubitFunction',
- 'QubitPhysicalObject',
- 'QubitStaticPage',
- 'QubitUser',
- 'QubitObjectTermRelation',
- 'QubitOtherName',
- 'QubitRelation',
- 'QubitAclGroup',
- 'QubitAclUserGroup',
- 'QubitAclPermission',
- 'QubitContactInformation',
- 'QubitMenu',
- 'QubitNote',
- 'QubitOaiRepository',
- 'QubitOaiHarvest',
- 'QubitProperty',
- 'QubitSetting'
- );
-
- $originalData = $this->data;
-
- foreach ($ormSortOrder as $i => $className)
- {
- if (isset($originalData[$className]))
- {
- $sortedData[$className] = $originalData[$className];
- unset($originalData[$className]);
- }
- }
-
- // If their are classes in the original data that are not listed in the
- // ormSortOrder array then tack them on to the end of the sorted data
- if (count($originalData))
- {
- foreach ($originalData as $className => $classData)
- {
- $sortedData[$className] = $classData;
- }
- }
-
- $this->data = $sortedData;
-
- return $this;
- }
-
- protected function getUniqueSlug($str)
- {
- $slug = $root = QubitSlug::slugify($str);
-
- for ($i = 0; $i < 100; $i++)
- {
- foreach ($this->data['QubitRepository'] as $item)
- {
- if (isset($item['slug']) && $item['slug'] == $slug)
- {
- $slug = $root.'-'.($i + 1);
-
- break;
- }
- }
-
- // If $slug hasn't been incremented this pass
- if ($slug == $root || $slug == $root.'-'.$i)
- {
- return $slug;
- }
- }
- }
}
--
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.