MigrationVersion::getVersion PHP Method

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
    public function getVersion($type)
    {
        $mapping = $this->getMapping($type);
        if ($mapping !== false) {
            krsort($mapping);
            foreach ($mapping as $version => $info) {
                if ($info['migrated'] !== null) {
                    return $version;
                }
            }
        }
        return 0;
    }

Usage Example

/**
 * 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'));
			}
		}
	}
All Usage Examples Of MigrationVersion::getVersion