public function __construct($login, $password, $host = 'localhost', $port = 3306)
 {
     if (extension_loaded('pdo_mysql')) {
         $this->mode = 'pdo';
         $this->db = new PDO('mysql:host=' . $host . ';port=' . $port, $login, $password);
         $this->db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
     } elseif (extension_loaded('mysqli')) {
         $this->mode = 'mysqli';
         $this->db = new mysqli($host, $login, $password, '', $port);
         if ($this->db->connect_error) {
             throw new pakeException('MySQLi Connect Error (' . $this->db->connect_errno . ') ' . $this->db->connect_error);
         }
     } elseif (extension_loaded('mysql')) {
         $this->mode = 'mysql';
         $this->db = mysql_connect($host . ':' . $port, $login, $password, true);
         if (false === $this->db) {
             throw new pakeException('MySQL Connect Error (' . mysql_errno() . ') ' . mysql_error());
         }
     } else {
         $this->mode = 'cli';
         $this->db = pake_which('mysqladmin');
         // will throw pakeException if not found
         $this->more = array('login' => $login, 'password' => $password, 'host' => $host, 'port' => $port);
     }
 }
Exemple #2
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');
    }
}
 public static function export($src_url, $target_path)
 {
     if (count(pakeFinder::type('any')->in($target_path)) > 0) {
         throw new pakeException('"' . $target_path . '" directory is not empty. Can not export there');
     }
     pake_echo_action('svn export', $target_path);
     if (extension_loaded('svn')) {
         $result = svn_export($src_url, $target_path, false);
         if (false === $result) {
             throw new pakeException('Couldn\'t export "' . $src_url . '" repository');
         }
     } else {
         pake_sh(escapeshellarg(pake_which('svn')) . ' export ' . escapeshellarg($src_url) . ' ' . escapeshellarg($target_path));
     }
 }
 public static function clone_repository($src_url, $target_path = null)
 {
     if (null === $target_path) {
         // trying to "guess" path
         $target_path = basename($src_url);
         // removing suffix
         if (substr($target_path, -3) === '.hg') {
             $target_path = substr($target_path, 0, -3);
         }
     }
     if (self::isRepository($target_path)) {
         throw new pakeException('"' . $target_path . '" directory is a Mercurial repository already');
     }
     if (file_exists($target_path)) {
         throw new pakeException('"' . $target_path . '" directory already exists. Can not clone Mercurial-repository there');
     }
     pake_mkdirs($target_path);
     pake_sh(escapeshellarg(pake_which('hg')) . ' clone -q ' . escapeshellarg($src_url) . ' ' . escapeshellarg($target_path));
     return new pakeMercurial($target_path);
 }
 public static function sync_from_server($local_path, $server_host, $remote_paths, $rsync_login = '', $transport = 'ssh')
 {
     if (strlen($rsync_login) > 0) {
         $rsync_login .= '@';
     }
     pake_mkdirs($local_path);
     if (is_string($remote_paths)) {
         // sync contents of dir, so adding trailing slash
         if ($remote_paths[strlen($remote_paths) - 1] != '/') {
             $remote_paths .= '/';
         }
         $remote_paths = array($remote_paths);
     } elseif (is_array($remote_paths)) {
         // syncing multiple objects, so removing trailing slashes
         $remote_paths = array_map(create_function('$path', 'return rtrim($path, "/");'), $remote_paths);
     }
     foreach ($remote_paths as &$remote_path) {
         $remote_path = $rsync_login . $server_host . ':' . $remote_path;
     }
     pake_sh(escapeshellarg(pake_which('rsync')) . ' -az -e ' . escapeshellarg($transport) . ' ' . implode(' ', array_map('escapeshellarg', $remote_paths)) . ' ' . escapeshellarg($local_path));
 }
 /**
  * Find a cli executable, looking first for configured binaries, then in $PATH and/or composer bin dir.
  * Takes proper care of adding windows suffixes to tool name when needed
  *
  * @param string $tool e.g. "git"
  * @param array $opts
  * @param bool $composerBinary when true, look in vendor/bin before $PATH
  * @return string
  */
 public static function getTool($tool, $opts = false, $composerBinary = false)
 {
     // dirty workaround
     if ($opts == false) {
         $opts = self::$options[self::$defaultExt];
     }
     if (isset($opts['tools'][$tool]) && is_string($opts['tools'][$tool]) && $opts['tools'][$tool] != '') {
         return escapeshellarg($opts['tools'][$tool]);
     } else {
         if (isset($opts['tools'][$tool]) && is_array($opts['tools'][$tool]) && isset($opts['tools'][$tool]['binary']) && $opts['tools'][$tool]['binary'] != '') {
             return escapeshellarg($opts['tools'][$tool]['binary']);
         } else {
             if ($composerBinary) {
                 $vendorDir = self::getVendorDir();
                 if (file_exists($vendorDir . "/bin/{$tool}")) {
                     $file = realpath($vendorDir . "/bin/{$tool}");
                     if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
                         $file .= '.bat';
                     }
                     return escapeshellarg($file);
                 }
             }
             return escapeshellarg(pake_which($tool));
         }
     }
 }
 public static function run__clean_build($task, $args, $long_args)
 {
     $dir = dirname(pakeApp::get_instance()->getPakefilePath());
     $cfg_file = $dir . '/' . __CLASS__ . '.yaml';
     if (file_exists('Makefile')) {
         pake_sh('make distclean');
     }
     if (file_exists('configure')) {
         if (isset($long_args['with-phpize'])) {
             $phpize = $long_args['with-phpize'];
         } elseif (file_exists($cfg_file)) {
             $cfg_data = pakeYaml::loadFile($cfg_file);
             $phpize = $cfg_data['phpize'];
         } else {
             $phpize = pake_which('phpize');
         }
         if (!file_exists($phpize)) {
             throw new pakeException('"' . $phpize . '" is not available');
         }
         pake_sh(escapeshellarg($phpize) . ' --clean');
     }
 }
 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(escapeshellarg(pake_which('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 true;
     }
     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) . ')');
     }
     return false;
 }
Exemple #9
0
 /**
  * Classifies all entries in git changelog as 4 types.
  * Each entry is returned starting with "- "
  * @return array the 1st-level elements are themselves matrixes, except for 'unmatchedEntries' which is a plain array
  */
 public static function extractChangelogEntriesFromRepo($rootpath, $previousrev)
 {
     if ($previousrev != '') {
         /// @todo check if given revision exists in git repo? We'll get an empty changelog if it does not...
         /// @todo replace with pakegit::log
         $git = escapeshellarg(pake_which('git'));
         $changelogArray = preg_split('/(\\r\\n|\\n\\r|\\r|\\n)/', pake_sh(self::getCdCmd($rootpath) . " && {$git} log --pretty=%s " . escapeshellarg($previousrev) . "..HEAD"));
         $changelogArray = array_map('trim', $changelogArray);
         foreach ($changelogArray as $i => $line) {
             if ($line == '') {
                 unset($changelogArray[$i]);
             }
         }
         $changelogText = implode("\n", $changelogArray);
         if ($changelogText == '') {
             pake_echo("Git log returns an empty string - generating an empty changelog file. Please check if there is any problem with {$rootpath}");
         }
         // Was: "extract and categorize issues using known patterns"
         // This proved not to be reliable!
         // We categorize all issues by looking at their type in the bug tracker instead
         /*preg_match_all( "/^[- ]?Fix(?:ed|ing)?(?: bug|issue|for ticket)? (EZP-[0-9]+):? (.*)$/mi", $changelogText, $bugfixesMatches, PREG_PATTERN_ORDER );
           preg_match_all( "/^[- ]?Implement(?:ed)?(?: enhancement|issue)? (EZP-[0-9]+):? (.*)$/mi", $changelogText, $enhancementsMatches, PREG_PATTERN_ORDER );*/
         preg_match_all("!^Merge pull request #0?([0-9]+):? ([^/]*)(?:/.*)?\$!mi", $changelogText, $pullreqsMatches, PREG_PATTERN_ORDER);
         // remove merge commits to get "unmatched" items
         $unmatchedEntries = array_diff($changelogArray, $pullreqsMatches[0]);
         /// if we identify an issue number, look up its type in jira to determine its type
         $issueTypes = array();
         foreach ($unmatchedEntries as $i => $entry) {
             if (preg_match('/(EZP-[0-9]+):? (.*)$/i', $entry, $matches)) {
                 if (isset($issueTypes[$matches[1]])) {
                     $type = $issueTypes[$matches[1]];
                 } else {
                     $type = self::findIssueType($matches[1]);
                     $issueTypes[$matches[1]] = $type;
                 }
                 switch ($type) {
                     case 'enhancement':
                         $enhancementsMatches[0][] = $matches[0];
                         $enhancementsMatches[1][] = $matches[1];
                         $enhancementsMatches[2][] = $matches[2];
                         unset($unmatchedEntries[$i]);
                         break;
                     case 'bugfix':
                         $bugfixesMatches[0][] = $matches[0];
                         $bugfixesMatches[1][] = $matches[1];
                         $bugfixesMatches[2][] = $matches[2];
                         unset($unmatchedEntries[$i]);
                         break;
                 }
             }
         }
         $unmatchedEntries = array_values(array_map(function ($item) {
             return substr($item, 0, 2) != "- " ? "- {$item}" : $item;
         }, $unmatchedEntries));
     } else {
         pake_echo('Can not determine the git tag of last version. Generating an empty changelog file');
         $bugfixesMatches = array(array());
         $enhancementsMatches = array(array());
         $pullreqsMatches = array(array());
         $unmatchedEntries = array();
     }
     return array('bugfixesMatches' => $bugfixesMatches, 'enhancementsMatches' => $enhancementsMatches, 'pullreqsMatches' => $pullreqsMatches, 'unmatchedEntries' => $unmatchedEntries);
 }
Exemple #10
0
function run_obs($task)
{
    run_release($task);
    $_root = dirname(__FILE__);
    $options = pakeYaml::loadFile($_root . '/options.yaml');
    $version = $options['version'];
    $target = $_root . '/target';
    pake_sh(escapeshellarg(pake_which('gunzip')) . ' ' . escapeshellarg($target . '/pake-' . $version . '.tgz'));
    pake_sh(escapeshellarg(pake_which('tar')) . ' -r -f ' . escapeshellarg($target . '/pake-' . $version . '.tar') . ' -C ' . escapeshellarg($_root) . ' debian');
    pake_sh(escapeshellarg(pake_which('gzip')) . ' ' . escapeshellarg($target . '/pake-' . $version . '.tar'));
}
Exemple #11
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);
}
Exemple #12
0
 public function execute($command)
 {
     return pake_sh(escapeshellarg(pake_which('ssh')) . ' -C ' . escapeshellarg($this->login . '@' . $this->host) . ' ' . escapeshellarg($command));
 }
 public static function install_from_file($file, $package_name, $channel = '__uri')
 {
     if (self::isInstalled($package_name, $channel)) {
         return true;
     }
     // otherwise, let's install it!
     $pear = escapeshellarg(pake_which('pear'));
     pake_superuser_sh($pear . ' install ' . escapeshellarg($file));
 }