Example #1
0
function cliMain($argv)
{
    $argc = count($argv);
    if ($argc < 2) {
        die("Usage: zombie.php <action> <option=value> ...\n" . "Availabe actions:\n" . "\tcompile\n" . "\tcreate-app\n");
    }
    $action = $argv[1];
    $options = array();
    for ($i = 2; $i < $argc; ++$i) {
        $opt = explode("=", $argv[$i], 2);
        if (count($opt) == 2) {
            $options[$opt[0]] = $opt[1];
        } else {
            $options[$opt[0]] = true;
        }
    }
    if ($action == "generate-app") {
        if (!isset($options['app'])) {
            die("Usage: zombie.php generate-app app=<app name> [template=<template_name>] [option=<value>] ...\n");
        }
        $template = isset($options['template']) ? $options['template'] : 'basic';
        $base_dir = "/config/generator";
        $template_file = realpath(__DIR__ . "/../config/generator/" . $template) . "/template.php";
        if (!file_exists($template_file)) {
            $base_dir = "/zombie-core/generator/";
            $template_file = __DIR__ . "/generator/" . $template . "/template.php";
            if (!file_exists($template_file)) {
                die("unknown template: " . $template . "\n");
            }
        }
        $app = $options['app'];
        require_once __DIR__ . "/generator/ZombieTemplate.php";
        require $template_file;
        $template_class = underscoreToClass($template . "_template");
        $template = new $template_class($template, $app, $base_dir, $options);
        $template->run();
    } else {
        if ($action == "compile") {
            require __DIR__ . "/util/compile/compile.php";
            compile($options);
        } else {
            if ($action == "migrate") {
                require __DIR__ . "/util/migrate/migrate.php";
                migrate($options);
            } else {
                if ($action == "deploy") {
                    require __DIR__ . "/util/deploy.php";
                    deploy();
                } else {
                    if ($action == "install-package") {
                        if (!isset($options['name'])) {
                            die("Usage: zombie.php install-package name=<package name>\n");
                        }
                        require __DIR__ . "/packages/installer.php";
                        installPackage($options['name']);
                    } else {
                        if ($action == "kachow") {
                            echo "kachow!\n";
                        } else {
                            echo "Error: unknown action '" . $action . "'.\n";
                        }
                    }
                }
            }
        }
    }
}
Example #2
0
                curl_setopt($ch, CURLOPT_TIMEOUT, 180);
                $safeMode = @ini_get('safe_mode');
                $openBasedir = @ini_get('open_basedir');
                if (empty($safeMode) && empty($openBasedir)) {
                    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
                }
                $file = curl_exec($ch);
                curl_close($ch);
            } else {
                return false;
            }
        }
        file_put_contents($dst, $file);
        return file_exists($dst);
    }
}
$packages = array('ModPNotify' => '1.0.0-beta', 'Ecc' => '1.0.2-beta');
foreach ($packages as $package_name => $version) {
    $installed = $modx->getIterator('transport.modTransportPackage', array('package_name' => $package_name));
    /** @var modTransportPackage $package */
    foreach ($installed as $package) {
        if ($package->compareVersion($version, '<=')) {
            continue 2;
        }
    }
    $modx->log(modX::LOG_LEVEL_INFO, "Trying to install <b>{$package_name}</b>. Please wait...");
    $response = installPackage($package_name);
    $level = $response['success'] ? modX::LOG_LEVEL_INFO : modX::LOG_LEVEL_ERROR;
    $modx->log($level, $response['message']);
}
return true;
Example #3
0
 $modx =& $object->xpdo;
 $success = false;
 switch ($options[xPDOTransport::PACKAGE_ACTION]) {
     case xPDOTransport::ACTION_INSTALL:
     case xPDOTransport::ACTION_UPGRADE:
         // Checking and installing required packages
         $packages = array('pdoTools' => array('version_major' => 1, 'version_minor:>=' => 9));
         foreach ($packages as $package => $options) {
             $query = array('package_name' => $package);
             if (!empty($options)) {
                 $query = array_merge($query, $options);
                 unset($query['service_url']);
             }
             if (!$modx->getObject('transport.modTransportPackage', $query)) {
                 $modx->log(modX::LOG_LEVEL_INFO, 'Trying to install <b>' . $package . '</b>. Please wait...');
                 $response = installPackage($package, $options);
                 if ($response['success']) {
                     $level = modX::LOG_LEVEL_INFO;
                 } else {
                     $level = modX::LOG_LEVEL_ERROR;
                 }
                 $modx->log($level, $response['message']);
             }
         }
         $success = true;
         break;
     case xPDOTransport::ACTION_UNINSTALL:
         $success = true;
         break;
 }
 return $success;