getVersion() public method

Get last version for given type
public getVersion ( string $type ) : integer
$type string Can be 'app' or a plugin name
return integer Last version migrated
/**
 * Shows a list of available migrations
 *
 * @param array $mapping Migration mapping
 * @param string $type Can be 'app' or a plugin name
 * @return void
 */
	protected function _showInfo($mapping, $type = null) {
		if ($type === null) {
			$type = $this->type;
		}

		$version = $this->Version->getVersion($type);
		if ($version != 0) {
			$info = $mapping[$version];
			$this->out(__d('Migrations', 'Current migration version:'));
			$this->out('  #' . number_format($version / 100, 2, '', '') . '  ' . $info['name']);
			$this->hr();
		}

		$this->out(__d('Migrations', 'Available migrations:'));
		foreach ($mapping as $version => $info) {
			$this->out('  [' . number_format($version / 100, 2, '', '') . '] ' . $info['name']);

			$this->out('        ', false);
			if ($info['migrated'] !== null) {
				$this->out(__d('Migrations', 'applied') . ' ' . date('r', strtotime($info['migrated'])));
			} else {
				$this->out(__d('Migrations', 'not applied'));
			}
		}
	}
 /**
  * testSetGetVersion method
  *
  * @return void
  */
 public function testSetGetVersion()
 {
     $this->Version = $this->getMock('MigrationVersion', array('getMapping'), array(array('connection' => 'test')));
     // Checking current
     $this->Version->expects($this->at(0))->method('getMapping')->will($this->returnValue($this->__mapping()));
     $result = $this->Version->getVersion('inexistent_plugin');
     $expected = 0;
     $this->assertEqual($result, $expected);
     // Setting as 1
     $this->Version->expects($this->at(0))->method('getMapping')->will($this->returnValue($this->__mapping()));
     $this->Version->expects($this->at(1))->method('getMapping')->will($this->returnValue($this->__mapping(1, 1)));
     $setResult = $this->Version->setVersion(1, 'inexistent_plugin');
     $this->assertTrue(!empty($setResult));
     $result = $this->Version->getVersion('inexistent_plugin');
     $expected = 1;
     $this->assertEqual($result, $expected);
     // Setting as 2
     $this->Version->expects($this->at(0))->method('getMapping')->will($this->returnValue($this->__mapping(1, 1)));
     $this->Version->expects($this->at(1))->method('getMapping')->will($this->returnValue($this->__mapping(1, 2)));
     $setResult = $this->Version->setVersion(2, 'inexistent_plugin');
     $this->assertTrue(!empty($setResult));
     $result = $this->Version->getVersion('inexistent_plugin');
     $expected = 2;
     $this->assertEqual($result, $expected);
     // Setting as 1
     $this->Version->expects($this->at(0))->method('getMapping')->will($this->returnValue($this->__mapping(1, 2)));
     $this->Version->expects($this->at(1))->method('getMapping')->will($this->returnValue($this->__mapping(1, 1)));
     $setResult = $this->Version->setVersion(2, 'inexistent_plugin', false);
     $this->assertTrue(!empty($setResult));
     $result = $this->Version->getVersion('inexistent_plugin');
     $expected = 1;
     $this->assertEqual($result, $expected);
 }
 /**
  * beforeRender Callback
  *
  * @return array
  */
 function beforeRender(&$controller)
 {
     $v = new MigrationVersion();
     $map = array();
     foreach (App::objects('plugin') as $plugin) {
         try {
             $map[$plugin] = array('map' => $v->getMapping($plugin), 'current' => $v->getVersion($plugin));
         } catch (MigrationVersionException $e) {
             // Skip if we get an error.
         }
     }
     return $map;
 }
 /**
  * BeforeRender Callback
  *
  * @param Controller $controller Current controller
  * @return array
  */
 public function beforeRender(Controller $controller)
 {
     $v = new MigrationVersion();
     $map = $migrations = array();
     $migrations = Hash::merge(array('app'), CakePlugin::loaded());
     foreach ($migrations as $plugin) {
         try {
             $map[$plugin] = array('map' => $v->getMapping($plugin), 'current' => $v->getVersion($plugin));
         } catch (MigrationVersionException $e) {
             // Skip if we get an error.
         }
     }
     return $map;
 }
 /**
  * testSetGetVersion method
  *
  * @return void
  */
 function testSetGetVersion()
 {
     $result = $this->Version->getVersion('inexistent_plugin');
     $expected = 0;
     $this->assertEqual($result, $expected);
     $this->assertTrue($this->Version->setVersion(1, 'inexistent_plugin'));
     $result = $this->Version->getVersion('inexistent_plugin');
     $expected = 1;
     $this->assertEqual($result, $expected);
     $this->assertTrue($this->Version->setVersion(2, 'inexistent_plugin'));
     $result = $this->Version->getVersion('inexistent_plugin');
     $expected = 2;
     $this->assertEqual($result, $expected);
     $this->assertTrue($this->Version->setVersion(2, 'inexistent_plugin', false));
     $result = $this->Version->getVersion('inexistent_plugin');
     $expected = 1;
     $this->assertEqual($result, $expected);
 }
Beispiel #6
0
 /**
  * Shows a list of available migrations
  *
  * @param array $mapping Migration mapping
  * @param string $type Can be 'app' or a plugin name
  * @return void
  */
 protected function _showInfo($mapping, $type = null)
 {
     if ($type === null) {
         $type = $this->type;
     }
     $version = $this->Version->getVersion($type);
     if ($version != 0) {
         $info = $mapping[$version];
         $this->out(__d('migrations', 'Current migration version:'));
         $this->out('  #' . sprintf("%'.03d", $version) . ' ' . $info['name']);
         $this->hr();
     }
     $this->out(__d('migrations', 'Available migrations:'));
     foreach ($mapping as $version => $info) {
         $this->out('  [' . sprintf("%'.03d", $version) . '] ' . $info['name']);
         $this->out('        ', false);
         if ($info['migrated'] !== null) {
             $this->out(__d('migrations', 'applied') . ' ' . CakeTime::nice(strtotime($info['migrated'])));
         } else {
             $this->out(__d('migrations', 'not applied'));
         }
     }
 }
 /**
 		* Temp acl things
 		protected function _getClassMethods($ctrlName = null) {
 			App::import('Controller', $ctrlName);
 			if (strlen(strstr($ctrlName, '.')) > 0) {
 				// plugin's controller
 				$num = strpos($ctrlName, '.');
 				$ctrlName = substr($ctrlName, $num+1);
 			}
 			$ctrlclass = $ctrlName . 'Controller';
 			$methods = get_class_methods($ctrlclass);
 
 			// Add scaffold defaults if scaffolds are being used
 			$properties = get_class_vars($ctrlclass);
 			if (is_array($properties) && array_key_exists('scaffold', $properties)) {
 				if($properties['scaffold'] == 'admin') {
 					$methods = array_merge($methods, array('admin_add', 'admin_edit', 'admin_index', 'admin_view', 'admin_delete'));
 				}
 			}
 
 			return $methods;
 		}
 
 		protected function _isPlugin($ctrlName = null) {
 			$arr = String::tokenize($ctrlName, '/');
 			if (count($arr) > 1) {
 				return true;
 			} else {
 				return false;
 			}
 		}
 
 		protected function _getPluginControllerPath($ctrlName = null) {
 			$arr = String::tokenize($ctrlName, '/');
 			if (count($arr) == 2) {
 				return $arr[0] . '.' . $arr[1];
 			} else {
 				return $arr[0];
 			}
 		}
 
 		protected function _getPluginName($ctrlName = null) {
 			$arr = String::tokenize($ctrlName, '/');
 			if (count($arr) == 2) {
 				return $arr[0];
 			} else {
 				return false;
 			}
 		}
 
 		protected function _getPluginControllerName($ctrlName = null) {
 			$arr = String::tokenize($ctrlName, '/');
 			if (count($arr) == 2) {
 				return $arr[1];
 			} else {
 				return false;
 			}
 		}
 
 		private function __getClassName() {
 			if (isset($this->request->params['plugin'])) {
 				return $this->request->plugin . '.' . $this->Controller->modelClass;
 			} else {
 				return $this->Controller->modelClass;
 			}
 		}
 
 		protected function _getPlugins(){
 			$plugins = array(
 				'infinitas',
 				'extentions',
 				'plugins'
 			);
 			$return = array();
 			foreach($plugins as $plugin ){
 				$return = array_merge($return, $this->_getPluginControllerNames($plugin));
 			}
 
 			return $return;
 		}
 
 		protected function _getPluginControllerNames($plugin) {
 			App::import('Core', 'File', 'Folder');
 			$paths = Configure::getInstance();
 			$folder = new Folder();
 			$folder->cd(APP . $plugin);
 
 			$Plugins = $folder->read();
 			$Plugins = $Plugins[0];
 
 			$arr = array();
 
 			// Loop through the plugins
 			foreach($Plugins as $pluginName) {
 				// Change directory to the plugin
 				$didCD = $folder->cd(APP . $plugin. DS . $pluginName . DS . 'controllers');
 				// Get a list of the files that have a file name that ends
 				// with controller.php
 				$files = $folder->findRecursive('.*_controller\.php');
 
 				// Loop through the controllers we found in the plugins directory
 				foreach($files as $fileName) {
 					// Get the base file name
 					$file = basename($fileName);
 
 					// Get the controller name
 					$file = Inflector::camelize(substr($file, 0, strlen($file)-strlen('_controller.php')));
 					if (!preg_match('/^'. Inflector::humanize($pluginName). 'App/', $file)) {
 						if (!App::import('Controller', $pluginName.'.'.$file)) {
 							debug('Error importing '.$file.' for plugin '.$pluginName);
 						} else {
 							/// Now prepend the Plugin name ...
 							// This is required to allow us to fetch the method names.
 							$arr[] = Inflector::humanize($pluginName) . "/" . $file;
 						}
 					}
 				}
 			}
 			return $arr;
 		}
 */
 public function checkDbVersion()
 {
     App::import('Lib', 'Migrations.MigrationVersion');
     $Version = new MigrationVersion();
     $currentVersion = $Version->getVersion('app');
     $latestVersion = end($Version->getMapping('app'));
     if ($currentVersion < $latestVersion['version']) {
         $this->Controller->redirect(array('plugin' => 'installer', 'controller' => 'upgrade', 'action' => 'index', 'admin' => true));
     }
 }