Author: david
Date: Thu May  3 15:20:36 2012
New Revision: 11613

Log:
Don't migrate data after Release 1.2

Modified:
   trunk/lib/task/migrate/MigrateTask.class.php

Modified: trunk/lib/task/migrate/MigrateTask.class.php
==============================================================================
--- trunk/lib/task/migrate/MigrateTask.class.php        Thu May  3 14:52:17 
2012        (r11612)
+++ trunk/lib/task/migrate/MigrateTask.class.php        Thu May  3 15:20:36 
2012        (r11613)
@@ -27,6 +27,9 @@
  */
 class MigrateTask extends sfBaseTask
 {
+  const
+    FINAL_VERSION = 75;
+
   protected
     $data,
     $dataModified = false,
@@ -77,25 +80,73 @@
       throw new Exception('The file '.$arguments['datafile'].' is not 
readable.');
     }
 
+    // load yml dumpfile into an array ($this->data)
+    $yamlParser = new sfYamlParser;
+    $this->data = 
$yamlParser->parse(file_get_contents($arguments['datafile']));
+
+    // Determine current version of the application (according to settings)
+    if (null !== $this->initialVersion = $this->getDataVersion())
+    {
+      $this->logSection('migrate', 'Initial data version 
'.$this->initialVersion);
+    }
+
+    if (self::FINAL_VERSION <= $this->initialVersion)
+    {
+      $this->logBlock(array(
+        '',
+        sprintf('ERROR: This migration script will only migrate your data to 
version Release 1.2 v%s.', self::FINAL_VERSION),
+        'To migrate to Release 1.3 or later, please see the upgrading 
documentation:',
+        '',
+        'http://qubit-toolkit.org/wiki/index.php?title=Upgrading',
+        '',
+        'Exiting!',
+        ''), 'ERROR');
+
+      return 1;
+    }
+
     // Get target application version for data migration
     if (isset($options['target-version']))
     {
-      if (!preg_match('/^\d+$/', $options['target-version']) && 
!in_array($options['target-version'], $this->validReleases))
+      if (in_array($options['target-version'], $this->validReleases))
       {
-        throw new Exception('Invalid target version 
"'.$options['target-version'].'".');
+        $this->targetVersion = $options['target-version'];
       }
 
-      $this->targetVersion = $options['target-version'];
-    }
+      else if (!preg_match('/^\d+$/', $options['target-version']))
+      {
+        $this->logBlock(sprintf('Invalid target version "%s".', 
$options['target-version']), 'ERROR');
 
-    // load yml dumpfile into an array ($this->data)
-    $yamlParser = new sfYamlParser;
-    $this->data = 
$yamlParser->parse(file_get_contents($arguments['datafile']));
+        return 1;
+      }
 
-    // Determine current version of the application (according to settings)
-    if (null !== $this->initialVersion = $this->getDataVersion())
+      // Version 75 is the last valid version for this migration script
+      if (self::FINAL_VERSION < intval($options['target-version']))
+      {
+        if (!$this->askConfirmation(array(
+          sprintf('WARNING: This migration script will only migrate your data 
to version Release 1.2 v%s', self::FINAL_VERSION),
+          'To migrate to Release 1.3 or later, please see upgrading 
documentation:',
+          '',
+          'http://qubit-toolkit.org/wiki/index.php?title=Upgrading',
+          '',
+          sprintf('Do you want to proceed with migrating your data to version 
%s (Y/n)?', self::FINAL_VERSION)
+          ), 'QUESTION_LARGE'))
+        {
+          $this->log('Halting migration.');
+
+          return 1;
+        }
+
+        $this->targetVersion = self::FINAL_VERSION;
+      }
+      else
+      {
+        $this->targetVersion = $options['target-version'];
+      }
+    }
+    else
     {
-      $this->logSection('migrate', 'Initial data version 
'.$this->initialVersion);
+      $this->targetVersion = self::FINAL_VERSION;
     }
 
     // At version 1.0.8 we switched from versioning by release to fine-grained
@@ -173,6 +224,7 @@
     {
       $this->version = $this->initialVersion;
     }
+
     else
     {
       $this->version = 0;
@@ -181,6 +233,7 @@
     while (null !== $this->version && (null === $this->targetVersion || 
$this->targetVersion > $this->version))
     {
       $migrator = QubitMigrateFactory::getMigrator($this->data, 
$this->version);
+
       $this->data = $migrator->execute();
       $this->dataModified = true;
 
@@ -195,7 +248,15 @@
       $this->version = $data['QubitSetting']['version']['value'];
     }
 
-    $this->logSection('migrate', 'Data migrated to Release 
'.$migrator::MILESTONE.' v'.$this->version);
+    $milestone = $migrator::MILESTONE;
+
+    // Hack for Release 1.2
+    if (self::FINAL_VERSION == $migrator::FINAL_VERSION)
+    {
+      $milestone = '1.2';
+    }
+
+    $this->logSection('migrate', 'Data migrated to Release '.$milestone.' 
v'.$this->version);
   }
 
   protected function writeMigratedData($originalFileName)
@@ -246,6 +307,7 @@
       if ('version' == $value['name'])
       {
         $version = $value['value'][$value['source_culture']];
+
         break;
       }
     }

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