Example #1
0
 /**
  * Execute the current command
  */
 private function execute()
 {
     _writeln('PHPLucidFrame %s by Sithu K.', _version());
     _writeln();
     if ($this->command instanceof \LucidFrame\Console\Command) {
         $this->command->run($this->argv);
     } else {
         if (!$this->command && $this->commandName && !in_array($this->commandName, array('-V', '--version'))) {
             _writeln('Command "%s" not found.', $this->commandName);
         } else {
             if (empty($this->command) || in_array($this->command, array('-V', '--version'))) {
                 _writeln(_version());
                 _writeln('PHP Version: %s', phpversion());
                 _writeln('The MIT License');
                 _writeln('Simple, lightweight & yet powerful PHP Application Framework');
                 _writeln('Copyright (c) 2014-%d, phplucidframe.com', date('Y'));
             } else {
                 _writeln('Command "%s" not found.', $this->commandName);
             }
         }
     }
 }
Example #2
0
function _migrate($param = null)
{
    global $versions, $config;
    if (!empty($config['rollback'])) {
        exit("\nexecution stopped");
    }
    //move to current version index
    $version = _version();
    if ($version) {
        if (!in_array($version, $versions)) {
            exit("\n{$version} doesn't match existing migrations");
        }
        reset($versions);
        $sync = array();
        //go to current version
        while (($tmp = current($versions)) !== false) {
            if (!in_array($tmp, $config['schema'])) {
                print "\n{$tmp}";
                $sync[] = $tmp;
                //catch up migrations
            }
            if ($tmp == $version) {
                echo "\ncurrent version: {$tmp}";
                break;
            } else {
                next($versions);
            }
        }
        if ($param > -1 && $sync) {
            echo "\nsync non-schema migrations";
            foreach ($sync as $tmp) {
                _single_migration($tmp);
                if (empty($config['rollback'])) {
                    $config['schema'][] = $tmp;
                    _version($version);
                } else {
                    exit("\nsync stopped");
                }
            }
        }
    }
    //process param
    if ($param === null) {
        $param = count($versions);
    } elseif (is_string($param)) {
        if (!in_array($param, $versions)) {
            die("\nno version '{$param}' matched");
        }
        echo "\ntarget migration {$param}";
        $param = array_search($param, $versions) - ($version ? array_search($version, $versions) : 0);
        echo " ({$param})";
    }
    //set direction and steps
    $step = 'next';
    if ($param < 0) {
        $step = 'prev';
        $param = -$param;
        if (!$version) {
            die("\ncan't migrate down");
        }
    } elseif (current($versions) == $version) {
        next($versions);
    }
    while ($param-- > 0) {
        $tmp = current($versions);
        $step($versions);
        if ($tmp !== false) {
            _single_migration($tmp, $step);
        } else {
            exit;
        }
    }
}