function run_propel_build_sql_diff($task, $args)
{
    if (!count($args)) {
        throw new Exception('You must provide the application.');
    }
    $app = $args[0];
    if (!is_dir(sfConfig::get('sf_app_dir') . DIRECTORY_SEPARATOR . $app)) {
        throw new Exception(sprintf('The app "%s" does not exist.', $app));
    }
    run_propel_build_sql($task, $args);
    pake_echo_action('propel-sql-diff', "building database patch");
    define('SF_ROOT_DIR', realpath(dirname(__FILE__) . '/../../../..'));
    define('SF_APP', $app);
    define('SF_ENVIRONMENT', isset($args[1]) ? $args[1] : 'dev');
    define('SF_DEBUG', 1);
    require_once SF_ROOT_DIR . DIRECTORY_SEPARATOR . 'apps' . DIRECTORY_SEPARATOR . SF_APP . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'config.php';
    $databaseManager = new sfDatabaseManager();
    $databaseManager->initialize();
    $i = new dbInfo();
    $i->loadFromDb();
    $i2 = new dbInfo();
    $i2->loadAllFilesInDir(sfConfig::get('sf_data_dir') . '/sql');
    $diff = $i->getDiffWith($i2);
    $filename = sfConfig::get('sf_data_dir') . '/sql/diff.sql';
    if ($diff == '') {
        pake_echo_comment("no difference found");
    }
    pake_echo_action('propel-sql-diff', "writing file {$filename}");
    file_put_contents($filename, $diff);
}
/**
 * Runs a gearman worker if it's not started yet
 *
 * Workers will be restarted by daemon automatically when they exit,
 * and they will exit after completing 1 task,
 * i.e. we don't use while($gmworker->work()) loop
 * @return void
 */
function run_start_gearman_worker()
{
    if (is_worker_running('gearman_worker')) {
        pake_echo_comment('Worker is running, no action needed.');
        return;
    }
    // daemon will respawn with bursts by 10 tries each (-A) with delay 10 sec between respawn bursts (-L)
    pake_shdir(get_run_worker_cmd('gearman_worker'), dirname(__FILE__) . WORKER_PATH);
    //pake_shdir(get_run_worker_cmd('gearman_worker2'), dirname(__FILE__) . WORKER_PATH);
}
Exemple #3
0
function run_default($task, $args)
{
    pake_echo_error('Installer is a separate tool now. Please use that');
    try {
        pake_which('mvc_install');
        pake_echo_comment('It is already installed on your system. Type: mvc_install');
    } catch (pakeException $e) {
        pake_echo_comment('I will install it for you…');
        pakePearTask::install_pear_package('midgardmvc_installer', 'pear.indeyets.pp.ru');
        pake_echo_comment('Done. To use it, type: mvc_install');
    }
}
Exemple #4
0
 /**
  * execute HTTP Request and match response against PCRE regexp
  *
  * @param string $regexp PCRE regexp
  * @param string $method 
  * @param string $url 
  * @param mixed $query_data string or array
  * @param mixed $body string or array
  * @param array $headers 
  * @param array $options 
  * @return void
  */
 public static function matchRequest($regexp, $method, $url, $query_data = null, $body = null, array $headers = array(), array $options = array())
 {
     $response = self::request($method, $url, $query_data, $body, $headers, $options);
     $result = preg_match($regexp, $response);
     if (false === $result) {
         throw new pakeException("There's some error with this regular expression: " . $regexp);
     }
     if (0 === $result) {
         throw new pakeException("HTTP Response didn't match against regular expression: " . $regexp);
     }
     pake_echo_comment('HTTP response matched against ' . $regexp);
 }
function run_import_users($task, $args)
{
    if (!isset($args[0])) {
        pake_echo_error('usage: pake i "users.yml"');
        return false;
    }
    pake_echo_comment("Reading file. It can take awhile…");
    $str = file_get_contents($args[0]);
    $data = pakeYaml::loadString($str);
    pake_echo_comment("Starting import…");
    $len = count($data);
    for ($i = 0; $i < $len; $i++) {
        $row = $data[$i];
        if (_create_user($row['login'], $row['password'], $row['data'])) {
            pake_echo_action('user+', "({$i} of {$len}) " . $row['login']);
        } else {
            pake_echo_comment('already exists: ' . "({$i} of {$len}) " . $row['login']);
        }
    }
}
 public static function run_app($task, $args)
 {
     if (isset($args[0])) {
         $config_file = $args[0];
     } else {
         $config_file = getcwd() . '/config.yaml';
     }
     pake_echo_comment('Loading configuration…');
     if (!file_exists($config_file)) {
         throw new \pakeException("Configuration file is not found: " . $config_file);
     }
     $config = \pakeYaml::loadFile($config_file);
     $runner = new Runner();
     foreach ($config['servers'] as $server) {
         if (!class_exists($server['app']['class'])) {
             require dirname($config_file) . '/' . $server['app']['file'];
             pake_echo_action('load class', $server['app']['class']);
         }
         $runner->addServer($server['app']['class'], $server['app']['middlewares'], $server['protocol'], $server['socket'], $server['min-children'], $server['max-children']);
         pake_echo_action('register', $server['app']['class'] . ' server via ' . $server['protocol'] . ' at ' . $server['socket'] . '. (' . $server['min-children'] . '-' . $server['max-children'] . ' children)');
     }
     pake_echo_comment('Starting server…');
     $runner->go();
 }
 public static function run_test($task)
 {
     $php_cgi = '';
     $_php_cgi = self::_get_php_executable() . '-cgi';
     if (file_exists($_php_cgi)) {
         $php_cgi = ' ' . escapeshellarg('TEST_PHP_CGI_EXECUTABLE=' . $_php_cgi);
     }
     pake_echo_comment('Running test-suite. This can take awhile…');
     pake_sh('make test NO_INTERACTION=1' . $php_cgi);
     pake_echo_comment('Done');
     $path = dirname(pakeApp::get_instance()->getPakefilePath()) . '/tests';
     $files = pakeFinder::type('file')->ignore_version_control()->relative()->name('*.diff')->in($path);
     if (count($files) == 0) {
         pake_echo('   All tests PASSed!');
         return;
     }
     pake_echo_error('Following tests FAILed:');
     foreach ($files as $file) {
         $phpt_file = substr($file, 0, -4) . 'phpt';
         $_lines = file($path . '/' . $phpt_file);
         $description = $_lines[1];
         unset($_lines);
         pake_echo('     ' . $phpt_file . ' (' . rtrim($description) . ')');
     }
 }
function pake_shdir($cmd, $dir, $interactive = false)
{
    $current_dir = realpath(getcwd());
    $dir = realpath($dir);
    pake_echo_comment("Jump into {$dir}");
    chdir($dir);
    try {
        $result = pake_sh($cmd, $interactive);
    } catch (Exception $e) {
        pake_echo_comment("Cd back into {$current_dir}");
        chdir($current_dir);
        throw $e;
    }
    pake_echo_comment("Jump back into {$current_dir}");
    chdir($current_dir);
    return $result;
}
Exemple #9
0
/**
 * release a new pake version
 *
 * @param string $task
 * @return bool
 * @author Alexey Zakhlestin
 */
function run_release($task)
{
    $_root = dirname(__FILE__);
    $options = pakeYaml::loadFile($_root . '/options.yaml');
    $version = $options['version'];
    pakeSimpletestTask::call_simpletest($task);
    if ($task->is_verbose()) {
        pake_echo_comment('releasing pake version "' . $version . '"');
    }
    run_create_pear_package();
}
Exemple #10
0
function pake_superuser_sh($cmd, $interactive = false)
{
    if (!isset($_SERVER['USER'])) {
        throw new pakeException("Don't know how to run commands as superuser");
    }
    // we're superuser already
    if ($_SERVER['USER'] === 'root') {
        return pake_sh($cmd, $interactive);
    }
    try {
        $sudo = pake_which('sudo');
        $cmd = escapeshellarg($sudo) . ' ' . $cmd;
    } catch (pakeException $e) {
        try {
            $su = pake_which('su');
            $cmd = escapeshellarg($su) . ' root -c ' . $cmd;
            $interactive = true;
            // force interactive, as su asks for password on stdout
        } catch (pakeException $e) {
            // no "sudo" and no "su". bad
            throw new pakeException("Don't know how to run commands as superuser");
        }
    }
    pake_echo_comment('Next command will be run using superuser priveleges');
    pake_sh($cmd, $interactive);
}
/**
 * Demo-task
 *
 * @param string $task
 * @param string $args
 * @return bool
 * @author Alexey Zakhlestin
 */
function run_foo($task, $args)
{
    $age = pake_input('How old are you?');
    pake_echo_comment("You are " . $age);
    // throw new Exception('test');
}
Exemple #12
0
function _upgrade_1_0_propel_ini()
{
    pake_echo_action('upgrade 1.0', 'upgrading propel.ini configuration file');
    $propel_file = sfConfig::get('sf_config_dir') . DIRECTORY_SEPARATOR . 'propel.ini';
    if (is_readable($propel_file)) {
        $updated = false;
        $propel_ini = file_get_contents($propel_file);
        $count = 0;
        // new target package (needed for new plugin system)
        $propel_ini = preg_replace('#propel\\.targetPackage(\\s*)=(\\s*)model#', 'propel.targetPackage$1=$2lib.model', $propel_ini, -1, $count);
        if ($count) {
            $updated = true;
        }
        $propel_ini = preg_replace('#propel.php.dir(\\s*)=(\\s*)\\${propel.output.dir}/lib#', 'propel.php.dir$1=$2\\${propel.output.dir}', $propel_ini, -1, $count);
        if ($count) {
            $updated = true;
        }
        if (false === strpos($propel_ini, 'propel.packageObjectModel')) {
            $updated = true;
            $propel_ini = rtrim($propel_ini);
            $propel_ini .= "\npropel.packageObjectModel = true\n";
        }
        // new propel builder class to be able to remove require_* and strip comments
        $propel_ini = str_replace('propel.engine.builder.om.php5.PHP5ExtensionObjectBuilder', 'addon.propel.builder.SfExtensionObjectBuilder', $propel_ini, $count);
        if ($count) {
            $updated = true;
        }
        $propel_ini = str_replace('propel.engine.builder.om.php5.PHP5ExtensionPeerBuilder', 'addon.propel.builder.SfExtensionPeerBuilder', $propel_ini, $count);
        if ($count) {
            $updated = true;
        }
        $propel_ini = str_replace('propel.engine.builder.om.php5.PHP5MultiExtendObjectBuilder', 'addon.propel.builder.SfMultiExtendObjectBuilder', $propel_ini, $count);
        if ($count) {
            $updated = true;
        }
        $propel_ini = str_replace('propel.engine.builder.om.php5.PHP5MapBuilderBuilder', 'addon.propel.builder.SfMapBuilderBuilder', $propel_ini, $count);
        if ($count) {
            $updated = true;
        }
        // replace old symfony.addon.propel path to addon.propel
        $propel_ini = str_replace('symfony.addon.propel.builder.', 'addon.propel.builder.', $propel_ini, $count);
        if ($count) {
            $updated = true;
        }
        if (false === strpos($propel_ini, 'addIncludes')) {
            $updated = true;
            $propel_ini .= <<<EOF

propel.builder.addIncludes  = false
propel.builder.addComments  = false
propel.builder.addBehaviors = false

EOF;
            pake_echo_comment('there are 3 new propel.ini options:');
            pake_echo_comment(' - propel.builder.addIncludes');
            pake_echo_comment(' - propel.builder.addComments');
            pake_echo_comment(' - propel.builder.addBehaviors');
        }
        if ($updated) {
            file_put_contents($propel_file, $propel_ini);
        }
    }
}