function run()
{
    session_start();
    require_once '../civicrm.config.php';
    require_once 'CRM/Core/Config.php';
    $config = CRM_Core_Config::singleton();
    require_once 'Console/Getopt.php';
    $shortOptions = "n:p:k:pre";
    $longOptions = array('name=', 'pass='******'key=', 'prefix=');
    $getopt = new Console_Getopt();
    $args = $getopt->readPHPArgv();
    array_shift($args);
    list($valid, $dontCare) = $getopt->getopt2($args, $shortOptions, $longOptions);
    $vars = array('name' => 'n', 'pass' => 'p', 'key' => 'k', 'prefix' => 'pre');
    foreach ($vars as $var => $short) {
        ${$var} = NULL;
        foreach ($valid as $v) {
            if ($v[0] == $short || $v[0] == "--{$var}") {
                ${$var} = $v[1];
                break;
            }
        }
        if (!${$var}) {
            ${$var} = CRM_Utils_Array::value($var, $_REQUEST);
        }
        $_REQUEST[$var] = ${$var};
    }
    // this does not return on failure
    // require_once 'CRM/Utils/System.php';
    CRM_Utils_System::authenticateScript(TRUE, $name, $pass);
    //log the execution of script
    CRM_Core_Error::debug_log_message('NormalizePhone.php');
    // process all phones
    processPhones($config, $prefix);
}
Example #2
0
 /**
  * constructor
  */
 function __construct($authenticate = true)
 {
     //	$include_path = "packages/" . get_include_path( );
     //	set_include_path( $include_path );
     if (!$authenticate) {
         $this->setEnv();
         return;
     }
     require_once 'Console/Getopt.php';
     $shortOptions = "s:u:p:";
     $longOptions = array('site=', 'user', 'pass');
     $getopt = new Console_Getopt();
     $args = $getopt->readPHPArgv();
     array_shift($args);
     list($valid, $this->args) = $getopt->getopt2($args, $shortOptions, $longOptions);
     $vars = array('user' => 'u', 'pass' => 'p', 'site' => 's');
     foreach ($vars as $var => $short) {
         ${$var} = null;
         foreach ($valid as $v) {
             if ($v[0] == $short || $v[0] == "--{$var}") {
                 ${$var} = $v[1];
                 break;
             }
         }
         if (!${$var}) {
             $a = explode('/', $_SERVER["SCRIPT_NAME"]);
             $file = $a[count($a) - 1];
             die("\nUsage: \$cd /your/civicrm/root; \$php5 bin/" . $file . " -u user -p password -s yoursite.org (or default)\n");
         }
     }
     $this->site = $site;
     $this->setEnv();
     $this->authenticate($user, $pass);
 }
Example #3
0
 /**
  * constructor
  */
 function __construct()
 {
     //	$include_path = "packages/" . get_include_path( );
     //	set_include_path( $include_path );
     require_once 'Console/Getopt.php';
     $shortOptions = "s:u:p:k:";
     $longOptions = array('site=', 'user', 'pass');
     $getopt = new Console_Getopt();
     $args = $getopt->readPHPArgv();
     array_shift($args);
     list($valid, $this->args) = $getopt->getopt2($args, $shortOptions, $longOptions);
     $vars = array('user' => 'u', 'pass' => 'p', 'key' => 'k', 'site' => 's');
     foreach ($vars as $var => $short) {
         ${$var} = NULL;
         foreach ($valid as $v) {
             if ($v[0] == $short || $v[0] == "--{$var}") {
                 ${$var} = $v[1];
                 break;
             }
         }
         if (!${$var}) {
             die("\nUsage: \$ php5 " . $_SERVER['PHP_SELF'] . " -k key -u user -p password -s yoursite.org\n");
         }
     }
     $this->site = $site;
     $this->key = $key;
     $this->setEnv();
     $this->authenticate($user, $pass);
 }
Example #4
0
 public function getParameters()
 {
     $params = array();
     sgAutoloader::loadFile('Console_Getopt', dirname(__FILE__) . '/vendor/Console/Getopt.php');
     $cg = new Console_Getopt();
     $params = $cg->readPHPArgv();
     array_shift($params);
     return $params;
 }
 public function __construct()
 {
     require_once 'Console/Getopt.php';
     define('NO_ARGS', 1);
     define('INVALID_OPTION', 2);
     $args = Console_Getopt::readPHPArgv();
     if (count($args) <= 1) {
         $this->usage(true);
         exit(1);
     }
     if (PEAR::isError($args)) {
         fputs(STDERR, $args->getMessage() . "\n");
         exit(NO_ARGS);
     }
     if ($_SERVER['argv'][0] == $_SERVER['SCRIPT_NAME']) {
         $this->opts = Console_Getopt::getOpt($args, $this->short_opts, $this->long_opts);
     } else {
         $this->opts = Console_Getopt::getOpt2($args, $this->short_opts, $this->long_opts);
     }
     // Are the passed options valid?
     if (PEAR::isError($this->opts)) {
         fputs(STDERR, $this->opts->getMessage() . "\n");
         exit(INVALID_OPTION);
     }
     $this->set_cache();
 }
Example #6
0
 /**
  * returns the commandline arguments of a function
  *
  * @param    string  $argv           the commandline
  * @param    string  $short_options  the allowed option short-tags
  * @param    string  $long_options   the allowed option long-tags
  * @return   array   the given options and there values
  * @access private
  */
 function _parseArgs($argv, $short_options, $long_options = null)
 {
     if (!is_array($argv) && $argv !== null) {
         $argv = preg_split('/\\s+/', ': ' . $argv);
     }
     return Console_Getopt::getopt($argv, $short_options);
 }
 /**
  * returns the commandline arguments of a function
  *
  * @param    string  $argv           the commandline
  * @param    string  $short_options  the allowed option short-tags
  * @param    string  $long_options   the allowed option long-tags
  * @return   array   the given options and there values
  * @static
  * @access private
  */
 function _parseArgs($argv, $short_options, $long_options = null)
 {
     if (!is_array($argv) && $argv !== null) {
         $argv = preg_split('/\\s+/', $argv, -1, PREG_SPLIT_NO_EMPTY);
     }
     return Console_Getopt::getopt2($argv, $short_options);
 }
Example #8
0
 /**
  * @param  array $arguments
  * @access protected
  */
 protected function start($arguments)
 {
     $wait = false;
     $possibleOptions = array('help', 'version', 'wait');
     $options = Console_Getopt::getopt($arguments, '', $possibleOptions);
     foreach ($options[0] as $option) {
         switch ($option[0]) {
             case '--help':
                 $this->showHelp();
                 exit(self::SUCCESS_EXIT);
                 break;
             case '--version':
                 print PHPUnit2_Runner_Version::getVersionString() . "\n";
                 exit(self::SUCCESS_EXIT);
                 break;
             case '--wait':
                 $wait = true;
                 break;
         }
     }
     $test = isset($options[1][0]) ? $options[1][0] : false;
     if ($test === false) {
         $this->showHelp();
         exit(self::SUCCESS_EXIT);
     }
     try {
         return $this->doRun($this->getTest($test), $wait);
     } catch (Exception $e) {
         throw new Exception('Could not create and run test suite: ' . $e->getMessage());
     }
 }
Example #9
0
function &get_commandline()
{
    $cg = new Console_Getopt();
    $args = $cg->readPHPArgv();
    array_shift($args);
    $shortOpts = 'h::v::';
    $longOpts = array('ini=', 'force==');
    $params = $cg->getopt2($args, $shortOpts, $longOpts);
    $new_params = array();
    foreach ($params[0] as $param) {
        $param[0] = str_replace('--', '', $param[0]);
        $new_params[$param[0]] = $param[1];
    }
    unset($params);
    return $new_params;
}
Example #10
0
 function raiseError($error)
 {
     $this->graph = new Image_GraphViz(true, array('fontname' => 'Verdana', 'fontsize' => 12.0, 'rankdir' => 'LR'));
     if (PEAR::isError($error)) {
         $error = $error->getMessage();
     }
     trigger_error($error, E_USER_WARNING);
     return Console_Getopt::getopt2($argv, $short_options);
 }
function &get_commandline()
{
    $cg = new Console_Getopt();
    $args = $cg->readPHPArgv();
    array_shift($args);
    $shortOpts = 'h::v::';
    $longOpts = array('ini=', 'help==', 'pid=', 'daemon==');
    $params = $cg->getopt2($args, $shortOpts, $longOpts);
    if (PEAR::isError($params)) {
        echo 'Error: ' . $params->getMessage() . "\n";
        exit(1);
    }
    $new_params = array();
    foreach ($params[0] as $param) {
        $param[0] = str_replace('--', '', $param[0]);
        $new_params[$param[0]] = $param[1];
    }
    unset($params);
    return $new_params;
}
Example #12
0
function run()
{
    session_start();
    require_once '../civicrm.config.php';
    require_once 'CRM/Core/Config.php';
    $config =& CRM_Core_Config::singleton();
    require_once 'Console/Getopt.php';
    $shortOptions = "n:p:s:e:k:";
    $longOptions = array('name=', 'pass='******'key=', 'start=', 'end=');
    $getopt = new Console_Getopt();
    $args = $getopt->readPHPArgv();
    array_shift($args);
    list($valid, $dontCare) = $getopt->getopt2($args, $shortOptions, $longOptions);
    $vars = array('start' => 's', 'end' => 'e', 'name' => 'n', 'pass' => 'p', 'key' => 'k');
    foreach ($vars as $var => $short) {
        ${$var} = null;
        foreach ($valid as $v) {
            if ($v[0] == $short || $v[0] == "--{$var}") {
                ${$var} = $v[1];
                break;
            }
        }
        if (!${$var}) {
            ${$var} = CRM_Utils_Array::value($var, $_REQUEST);
        }
        $_REQUEST[$var] = ${$var};
    }
    // this does not return on failure
    // require_once 'CRM/Utils/System.php';
    CRM_Utils_System::authenticateScript(true, $name, $pass);
    // check that we have a geocodeMethod
    if (empty($config->geocodeMethod)) {
        echo ts('Error: You need to set a mapping provider under Global Settings');
        exit;
    }
    $config->userFramework = 'Soap';
    $config->userFrameworkClass = 'CRM_Utils_System_Soap';
    $config->userHookClass = 'CRM_Utils_Hook_Soap';
    // we have an exclusive lock - run the mail queue
    processContacts($config, $start, $end);
}
 public function executeDoctrineCli($arguments = array(), $options = array())
 {
     try {
         DoctrinePluginConfiguration::init();
     } catch (Exception $e) {
         sgCLI::error($e->getMessage());
         return false;
     }
     // spl_autoload_register(array('Doctrine', 'modelsAutoload'));
     spl_autoload_register(array('Doctrine', 'extensionsAutoload'));
     $settings = sgConfiguration::get('settings.DoctrinePlugin');
     $settings['generate_models_options']['suffix'] = '.class.php';
     $config = array('data_fixtures_path' => DoctrinePluginConfiguration::getPath('fixtures'), 'models_path' => DoctrinePluginConfiguration::getPath('models'), 'migrations_path' => DoctrinePluginConfiguration::getPath('mogrations'), 'sql_path' => DoctrinePluginConfiguration::getPath('sql'), 'yaml_schema_path' => DoctrinePluginConfiguration::getPath('schema'), 'generate_models_options' => $settings['generate_models_options']);
     $cg = new Console_Getopt();
     $params = $cg->readPHPArgv();
     $params[0] .= ' ' . $params[1];
     unset($params[1]);
     $params = array_merge($params);
     $cli = new DoctrinePluginCli($config);
     $cli->run($params);
 }
Example #14
0
 /**
  * Constructor will parse specified short and long arguments
  *
  * @access public
  * @param  string   short options specification
  * @param  array    long options specification
  * @param  callback error callback, call this and exit on errors if given
  */
 function __construct($short_options, $long_options = NULL, $usage = NULL)
 {
     // use parent methods for actual parsing, store result internaly
     $argv = parent::readPHPArgv();
     $this->options = parent::getopt($argv, $short_options, $long_options);
     if (PEAR::isError($this->options)) {
         if (!is_null($usage) && is_callable($usage)) {
             call_user_func($usage, $this->options->message);
             exit(3);
         }
     }
 }
Example #15
0
function &get_commandline($more_longopts = array())
{
    $cg = new Console_Getopt();
    $args = $cg->readPHPArgv();
    array_shift($args);
    $shortOpts = 'h::v::';
    $longOpts = array('user='******'ini=', 'password='******'host=', 'db=', 'port=', 'help==', 'verbose==', 'method=', 'gearman=', 'inlist=', 'between=', 'directory=', 'push_where', 'inlist_merge_threshold==', 'inlist_merge_size==', 'coord_engine==', 'schema=', 'batch');
    $longOpts = array_merge($longOpts, $more_longopts);
    @($params = $cg->getopt2($args, $shortOpts, $longOpts));
    if (@PEAR::isError($params)) {
        echo 'Error: ' . $params->getMessage() . "\n";
        exit(1);
    }
    $new_params = array();
    foreach ($params[0] as $param) {
        $param[0] = str_replace('--', '', $param[0]);
        $new_params[$param[0]] = $param[1];
    }
    unset($params);
    return $new_params;
}
Example #16
0
 function get($path)
 {
     ini_set('memory_limit', '256M');
     // we need alot of memory
     set_time_limit(0);
     $argv = $_SERVER['argv'];
     array_shift($argv);
     array_shift($argv);
     $opts = explode(',', 'table==,where==,dump-dir==,debug=');
     require_once 'Console/Getopt.php';
     $go = Console_Getopt::getopt2($argv, '', $opts);
     if (is_object($go)) {
         die($go->toString());
     }
     foreach ($go[0] as $ar) {
         $args[substr($ar[0], 2)] = $ar[1];
     }
     $errs = array();
     foreach ($opts as $req) {
         if (substr($req, -2, 2) != '==') {
             // skip optional arguments
             continue;
         }
         if (empty($args[substr($req, 0, -2)])) {
             $errs[] = "--" . substr($req, 0, -2) . ' is required';
         }
     }
     if (!empty($errs)) {
         die(print_R($errs, true));
     }
     if (!empty($args['debug'])) {
         DB_DataObject::debugLevel($args['debug']);
     }
     $this->args = $args;
     $this->out = array();
     $this->discoverChildren($this->args['table'], $this->args['where'], true);
     //print_R($this->deletes);
     //print_r($this->dumps);
     //exit;
     $this->discover($this->args['table'], $this->args['where'], true);
     if (!file_exists($args['dump-dir'])) {
         mkdir($args['dump-dir'], 0777, true);
     }
     // create uid's
     // dump items..
     echo "GENERATED FILES:\n";
     // summary
     echo "    " . implode("\n    ", $this->out) . "\n";
     exit;
 }
Example #17
0
 /**
  *
  */
 public function getParams()
 {
     $short_opts = 'hdcsl';
     $long_opts = array('help', 'debug', 'compress', 'strict', 'lexdebug');
     $console = new Console_Getopt();
     $args = $console->readPHPArgv();
     $opts = $console->getopt($args, $short_opts, $long_opts);
     if (PEAR::isError($opts)) {
         echo $opts->getMessage() . PHP_EOL;
         $this->usage(1);
     }
     foreach ($opts[0] as $opt) {
         if ($opt[0] === '--help' || $opt[0] === 'h') {
             $this->usage();
         }
         if ($opt[0] === '--debug' || $opt[0] === 'd') {
             SmartCSS::$debug = true;
         }
         if ($opt[0] === '--compress' || $opt[0] === 'c') {
             SmartCSS::$compress = true;
         }
         if ($opt[0] === '--strict' || $opt[0] === 's') {
             SmartCSS::$strict = true;
         }
         if ($opt[0] === '--lexdebug' || $opt[0] === 'l') {
             SmartCSS::$lexdebug = true;
         }
     }
     if (empty($opts[1])) {
         $this->usage();
     }
     $filename = $opts[1][0];
     if (empty($filename)) {
         $this->usage();
     }
     return $filename;
 }
  function run(&$root_group)
  {
    $opt_browse_path = false;
    $opt_test_path = false;

    $argv = Console_Getopt::readPHPArgv();
    if (PEAR::isError($argv))
    {
      die('Fatal Error: ' . $argv->getMessage()) . "\n";
    }

    $short_opts = 'ht:b:';
    $long_opts = array('help', 'test=', 'browse=');
    $options = Console_Getopt::getopt($argv, $short_opts, $long_opts);
    if (PEAR::isError($options))
    {
      $this->usage();
    }

    foreach ($options[0] as $option)
    {
      switch ($option[0])
      {
        case 'h':
        case '--help':
          $this->usage();
          break;
        case 't':
        case '--test':
          $opt_test_path = $option[1];
          break;
        case 'b':
        case '--browse':
          $opt_browse_path = $option[1];
          break;
      }
    }

    if ($opt_browse_path)
      $this->browse($opt_browse_path, $root_group);

    if ($opt_test_path)
      $this->perform($opt_test_path, $root_group);

    if(!$opt_browse_path && !$opt_test_path)
      $this->browse('', $root_group);

    exit(0);
  }
Example #19
0
 /**
  * returns the commandline arguments of a function
  *
  * @param    string  $argv           the commandline
  * @param    string  $short_options  the allowed option short-tags
  * @param    string  $long_options   the allowed option long-tags
  * @return   array   the given options and there values
  * @static
  * @access private
  */
 static function _parseArgs($argv, $short_options, $long_options = null)
 {
     if (!is_array($argv) && $argv !== null) {
         // Find all items, quoted or otherwise
         preg_match_all("/(?:[\"'])(.*?)(?:['\"])|([^\\s]+)/", $argv, $av);
         $argv = $av[1];
         foreach ($av[2] as $k => $a) {
             if (empty($a)) {
                 continue;
             }
             $argv[$k] = trim($a);
         }
     }
     return Console_Getopt::getopt2($argv, $short_options, $long_options);
 }
Example #20
0
 function parseArgs()
 {
     // mapp of keys to values..
     $args = Console_Getopt::ReadPHPArgV();
     $vals = Console_Getopt::getopt($args, '');
     //print_r($vals);
     $files = $vals[1];
     if (!$files) {
         $this->error(0, "No Files supplied");
     }
     foreach ($files as $file) {
         $realpath = realpath($file);
         if (!$realpath) {
             $this->error(0, "File {$path} Does not exist");
         }
         $this->files[] = $realpath;
     }
 }
Example #21
0
 public static function main()
 {
     $options = Console_Getopt::getopt($_SERVER['argv'], '', array('wait'));
     if (PEAR::isError($options)) {
         // ...
         exit;
     }
     $test = isset($options[1][0]) ? $options[1][0] : false;
     $wait = isset($options[0][0][0]) ? true : false;
     if ($test) {
         $testRunner = new PHPUnit_TextUI_TestRunner();
         try {
             $result = $testRunner->doRun($testRunner->getTest($test), $wait);
         } catch (Exception $e) {
             // ...
         }
     } else {
         // ...
     }
 }
Example #22
0
 protected function parseParams($namespace, $task, $cliParams = array())
 {
     sgAutoloader::loadFile('Console_Getopt', dirname(__FILE__) . '/vendor/Console/Getopt.php');
     $arguments = array();
     $options = array();
     $taskDefinition = self::getTask($namespace, $task);
     if (isset($taskDefinition['options']) || isset($taskDefinition['arguments'])) {
         if (!isset($taskDefinition['arguments'])) {
             $taskDefinition['arguments'] = array();
         }
         if (!isset($taskDefinition['options']['short'])) {
             $taskDefinition['options']['short'] = null;
         }
         if (!isset($taskDefinition['options']['long'])) {
             $taskDefinition['options']['long'] = array();
         }
         try {
             $params = Console_Getopt::getopt($cliParams, $taskDefinition['options']['short'], $taskDefinition['options']['long']);
             if (!empty($taskDefinition['arguments']) && (!isset($params[1]) || count($taskDefinition['arguments']) !== count($params[1]))) {
                 throw new Exception('Missing required argument.');
             }
             $arguments = array();
             if (!empty($taskDefinition['arguments'])) {
                 $arguments = array_combine($taskDefinition['arguments'], $params[1]);
             }
             $options = array();
             foreach ($params[0] as $param) {
                 $options[$param[0]] = $param[1];
             }
         } catch (Exception $e) {
             $error = array();
             $error[] = $e->getMessage();
             if (isset($taskDefinition['usage'])) {
                 $error[] = 'Usage: ' . $taskDefinition['usage'];
             }
             sgCLI::error($error);
             return false;
         }
     }
     return array('arguments' => $arguments, 'options' => $options);
 }
 public function __construct()
 {
     $args = Console_Getopt::readPHPArgv();
     if (PEAR::isError($args)) {
         fwrite(STDERR, $args->getMessage() . "\n");
         exit(1);
     }
     // Compatibility between "php script.php" and "./script.php"
     if (realpath($_SERVER['argv'][0]) == __FILE__) {
         $this->options = Console_Getopt::getOpt($args, $this->short_format_config);
     } else {
         $this->options = Console_Getopt::getOpt2($args, $this->short_format_config);
     }
     // Check for invalid options
     if (PEAR::isError($this->options)) {
         fwrite(STDERR, $this->options->getMessage() . "\n");
         $this->help();
     }
     $this->command = array();
     // Loop through the user provided options
     foreach ($this->options[0] as $option) {
         switch ($option[0]) {
             case 'h':
                 help();
                 break;
             case 's':
                 $this->command['syntax'] = $option[1];
                 break;
             case 't':
                 $this->command['transform'] = $option[1];
                 break;
             case 'c':
                 $this->command['config'] = $option[1];
                 break;
         }
     }
     // Loop through the user provided options
     foreach ($this->options[1] as $argument) {
         $this->command['query'] .= ' ' . $argument;
     }
 }
Example #24
0
/**
 * This script parses MIME messages and deactivates users with returned emails.
 *
 * Copyright 2008-2014 Horde LLC (http://www.horde.org/)
 *
 * See the enclosed file COPYING for license information (GPL). If you
 * did not receive this file, see http://www.horde.org/licenses/gpl.
 *
 * @author  Duck <*****@*****.**>
 * @package Folks
 */
function usage()
{
    $argv = Console_Getopt::readPHPArgv();
    $cmd = basename($argv[0]);
    echo <<<EOU
Usage: {$cmd} [options]

This script parses MIME messages and deactivates users with returned emails.

Options:
    -h, --help           Give this help.
    -u, --username       A user to send notificatons with.
        --mail-host      The IMAP/POP3 server to get the messages from.
                         Defaults to "localhost".
        --mail-user      The user name for the mail server.
        --mail-pass      The password for the mail server.
        --mail-port      The mail server port. Defaults to "143".
        --mail-protocol  The mail server protocol. Defaults to "imap/notls".
        --mail-folder    The folder on the mail server. Defaults to "INBOX".

EOU;
}
Example #25
0
/**
 * Main functions. Just decides what mode we are in and calls the
 * appropriate methods.
 */
function main()
{
    global $info, $config;
    $args = Console_Getopt::readPHPArgv();
    if (count($args) < 2) {
        print_usage_info();
    }
    if (substr($args[1], 0, 1) == "-" || substr($args[1], 0, 1) == "/") {
        print "invalid parameter " . $args[2] . "\n";
        print_usage_info();
    }
    if (substr($args[1], -4) == ".php") {
        // mode 2: create zombie app
        if (!file_exists($args[1])) {
            die("config file " . $args[1] . " does not exist\n");
        }
        read_config_file($args[1]);
        $outdir = ZOMBIE_BASE . '/../' . Horde_String::lower($config['app']);
        if (is_dir($outdir) && $args[2] != "-f") {
            print "Directory {$outdir} already exists.\nUse -f flag to force overwrite\n";
            exit;
        }
        $n = $config['app'];
        print "Creating Horde Application {$n} in directory " . Horde_String::lower($n) . "\n";
        transform($outdir);
        print "\nHorde Application '{$n}' successfully written. Where to go from here:\n" . "1) Paste content of {$n}/registry.stub to horde/config/registry.php.\n" . "   After that, the {$n} should be working!\n" . "2) Replace {$n}.gif with proper application icon\n" . "3) Ensure conf.php is not world-readable as it may contain password data.\n" . "4) Start playing around and enhancing your new horde application. Enjoy!\n";
    } else {
        // mode 1: create config file
        parse_options($args);
        print "creating config file for table " . $config['table'] . "\n";
        create_table_info();
        enhance_info();
        print "writing config file to " . $config['file'] . "\n";
        dump_config_file();
    }
}
 /**
  * The actual implementation of the argument parsing code.
  */
 function doGetopt($version, $args, $short_options, $long_options = null)
 {
     // in case you pass directly readPHPArgv() as the first arg
     if (PEAR::isError($args)) {
         return $args;
     }
     if (empty($args)) {
         return array(array(), array());
     }
     $opts = array();
     $non_opts = array();
     settype($args, 'array');
     if ($long_options) {
         sort($long_options);
     }
     /*
      * Preserve backwards compatibility with callers that relied on
      * erroneous POSIX fix.
      */
     if ($version < 2) {
         if (isset($args[0][0]) && $args[0][0] != '-') {
             array_shift($args);
         }
     }
     reset($args);
     while (list($i, $arg) = each($args)) {
         /* The special element '--' means explicit end of
            options. Treat the rest of the arguments as non-options
            and end the loop. */
         if ($arg == '--') {
             $non_opts = array_merge($non_opts, array_slice($args, $i + 1));
             break;
         }
         if ($arg[0] != '-' || strlen($arg) > 1 && $arg[1] == '-' && !$long_options) {
             $non_opts = array_merge($non_opts, array_slice($args, $i));
             break;
         } elseif (strlen($arg) > 1 && $arg[1] == '-') {
             $error = Console_Getopt::_parseLongOption(substr($arg, 2), $long_options, $opts, $args);
             if (PEAR::isError($error)) {
                 return $error;
             }
         } else {
             $error = Console_Getopt::_parseShortOption(substr($arg, 1), $short_options, $opts, $args);
             if (PEAR::isError($error)) {
                 return $error;
             }
         }
     }
     return array($opts, $non_opts);
 }
Example #27
0
 /**
  * Returns profiling information gathered using APD functions.
  * Accepts a numerical array of command-line arguments.
  * 
  * Profiler::get_profiling($args)
  *  Sort options
  *  -a          Sort by alphabetic names of subroutines.
  *  -l          Sort by number of calls to subroutines
  *  -m          Sort by memory used in a function call.
  *  -r          Sort by real time spent in subroutines.
  *  -R          Sort by real time spent in subroutines (inclusive of child calls).
  *  -s          Sort by system time spent in subroutines.
  *  -S          Sort by system time spent in subroutines (inclusive of child calls).
  *  -u          Sort by user time spent in subroutines.
  *  -U          Sort by user time spent in subroutines (inclusive of child calls).
  *  -v          Sort by average amount of time spent in subroutines.
  *  -z          Sort by user+system time spent in subroutines. (default)
  *
  *  Display options
  *  -c          Display Real time elapsed alongside call tree.
  *  -i          Suppress reporting for php builtin functions
  *  -O <cnt>    Specifies maximum number of subroutines to display. (default 15)
  *  -t          Display compressed call tree.
  *  -T          Display uncompressed call tree.
  *
  *  Example array: array('-a', '-l');
  *   
  * @param Array $args
  * @return String Profiling info
  */
 function get_profiling($args)
 {
     $con = new Console_Getopt();
     array_shift($args);
     $shortoptions = 'acg:hiIlmMrRsStTuUO:vzZ';
     $retval = $con->getopt($args, $shortoptions);
     if (is_object($retval)) {
         usage();
     }
     $opt['O'] = 20;
     foreach ($retval[0] as $kv_array) {
         $opt[$kv_array[0]] = $kv_array[1];
     }
     $DATA = Profiler::_get_pprofp();
     $cfg = array();
     $this->parse_info('HEADER', $DATA, $cfg);
     $callstack = array();
     $calls = array();
     $indent_cur = 0;
     $file_hash = array();
     $this->mem = array();
     $t_rtime = 0;
     $t_stime = 0;
     $t_utime = 0;
     $c_rtimes = array();
     $this->c_stimes = array();
     $this->c_utimes = array();
     $rtimes = array();
     $this->stimes = array();
     $this->utimes = array();
     $rtotal = 0;
     $stotal = 0;
     $utotal = 0;
     $last_memory = 0;
     $symbol_hash = array();
     $symbol_type = array();
     while ($line = fgets($DATA)) {
         $line = rtrim($line);
         if (preg_match("/^END_TRACE/", $line)) {
             break;
         }
         list($token, $data) = preg_split("/ /", $line, 2);
         if ($token == '!') {
             list($index, $file) = preg_split("/ /", $data, 2);
             $file_hash[$index] = $file;
             continue;
         }
         if ($token == '&') {
             list($index, $name, $type) = preg_split("/ /", $data, 3);
             $symbol_hash[$index] = $name;
             $symbol_type[$index] = $type;
             continue;
         }
         if ($token == '+') {
             list($index, $file, $line) = preg_split("/ /", $data, 3);
             if (array_key_exists('i', $opt) && $symbol_type[$index] == 1) {
                 continue;
             }
             $index_cur = $index;
             $calls[$index_cur]++;
             array_push($callstack, $index_cur);
             if (array_key_exists('T', $opt)) {
                 if (array_key_exists('c', $opt)) {
                     $retstring .= sprintf("%2.02f ", $rtotal / 1000000);
                 }
                 $retstring .= str_repeat("  ", $indent_cur) . $symbol_hash[$index_cur] . "\n";
                 if (array_key_exists('m', $opt)) {
                     $retstring .= str_repeat("  ", $indent_cur) . "C: {$file_hash[$file]}:{$line} M: {$memory}\n";
                 }
             } elseif (array_key_exists('t', $opt)) {
                 if ($indent_last == $indent_cur && $index_last == $index_cur) {
                     $repcnt++;
                 } else {
                     if ($repcnt) {
                         $repstr = ' (' . ++$repcnt . 'x)';
                     }
                     if (array_key_exists('c', $opt)) {
                         $retstring .= sprintf("%2.02f ", $rtotal / 1000000);
                     }
                     $retstring .= str_repeat("  ", $indent_last) . $symbol_hash[$index_last] . $repstr . "\n";
                     if (array_key_exists('m', $opt)) {
                         $retstring .= str_repeat("  ", $indent_cur) . "C: {$file_hash[$file_last]}:{$line_last} M: {$memory}\n";
                     }
                     $repstr = '';
                     $repcnt = 0;
                     $index_last = $index_cur;
                     $indent_last = $indent_cur;
                     $file_last = $file;
                     $line_last = $line;
                 }
             }
             $indent_cur++;
             continue;
         }
         if ($token == '@') {
             list($file_no, $line_no, $ut, $st, $rt) = preg_split("/ /", $data);
             $top = array_pop($callstack);
             $this->utimes[$top] += $ut;
             $utotal += $ut;
             $this->stimes[$top] += $st;
             $stotal += $st;
             $rtimes[$top] += $rt;
             $rtotal += $rt;
             array_push($callstack, $top);
             foreach ($callstack as $stack_element) {
                 $this->c_utimes[$stack_element] += $ut;
                 $this->c_stimes[$stack_element] += $st;
                 $c_rtimes[$stack_element] += $rt;
             }
             continue;
         }
         if ($token == '-') {
             list($index, $memory) = preg_split("/ /", $data, 2);
             if (array_key_exists('i', $opt) && $symbol_type[$index] == 1) {
                 continue;
             }
             $this->mem[$index] += $memory - $last_memory;
             $last_memory = $memory;
             $indent_cur--;
             $tmp = array_pop($callstack);
             continue;
         }
     }
     $this->parse_info('FOOTER', $DATA, $cfg);
     $sort = 'by_time';
     if (array_key_exists('l', $opt)) {
         $sort = 'by_calls';
     }
     if (array_key_exists('m', $opt)) {
         $sort = 'by_mem';
     }
     if (array_key_exists('a', $opt)) {
         $sort = 'by_name';
     }
     if (array_key_exists('v', $opt)) {
         $sort = 'by_avgcpu';
     }
     if (array_key_exists('r', $opt)) {
         $sort = 'by_rtime';
     }
     if (array_key_exists('R', $opt)) {
         $sort = 'by_c_rtime';
     }
     if (array_key_exists('s', $opt)) {
         $sort = 'by_stime';
     }
     if (array_key_exists('S', $opt)) {
         $sort = 'by_c_stime';
     }
     if (array_key_exists('u', $opt)) {
         $sort = 'by_utime';
     }
     if (array_key_exists('U', $opt)) {
         $sort = 'by_c_utime';
     }
     if (array_key_exists('Z', $opt)) {
         $sort = 'by_c_time';
     }
     if (!count($symbol_hash)) {
         continue;
     }
     $retstring .= sprintf("\n        Trace for %s\n        Total Elapsed Time = %4.2f\n        Total System Time  = %4.2f\n        Total User Time    = %4.2f\n        ", $cfg['caller'], $rtotal / 1000000, $stotal / 1000000, $utotal / 1000000);
     $retstring .= "\n\n                 Real         User        System             secs/    cumm\n        %Time (excl/cumm)  (excl/cumm)  (excl/cumm) Calls    call    s/call  Memory Usage Name\n        --------------------------------------------------------------------------------------\n";
     $l = 0;
     $itotal = 0;
     $percall = 0;
     $cpercall = 0;
     uksort($symbol_hash, $sort);
     foreach (array_keys($symbol_hash) as $j) {
         if (array_key_exists('i', $opt) && $symbol_type[$j] == 1) {
             continue;
         }
         if ($l++ < $opt['O']) {
             $pcnt = 100 * ($this->stimes[$j] + $this->utimes[$j]) / ($utotal + $stotal + $itotal);
             $c_pcnt = 100 * ($this->c_stimes[$j] + $this->c_utimes[$j]) / ($utotal + $stotal + $itotal);
             $rsecs = $rtimes[$j] / 1000000;
             $ssecs = $this->stimes[$j] / 1000000;
             $usecs = $this->utimes[$j] / 1000000;
             $c_rsecs = $c_rtimes[$j] / 1000000;
             $c_ssecs = $this->c_stimes[$j] / 1000000;
             $c_usecs = $this->c_utimes[$j] / 1000000;
             $ncalls = $calls[$j];
             if (array_key_exists('z', $opt)) {
                 $percall = ($usecs + $ssecs) / $ncalls;
                 $cpercall = ($c_usecs + $c_ssecs) / $ncalls;
                 if ($utotal + $stotal) {
                     $pcnt = 100 * ($this->stimes[$j] + $this->utimes[$j]) / ($utotal + $stotal);
                 } else {
                     $pcnt = 100;
                 }
             }
             if (array_key_exists('Z', $opt)) {
                 $percall = ($usecs + $ssecs) / $ncalls;
                 $cpercall = ($c_usecs + $c_ssecs) / $ncalls;
                 if ($utotal + $stotal) {
                     $pcnt = 100 * ($this->c_stimes[$j] + $this->c_utimes[$j]) / ($utotal + $stotal);
                 } else {
                     $pcnt = 100;
                 }
             }
             if (array_key_exists('r', $opt)) {
                 $percall = $rsecs / $ncalls;
                 $cpercall = $c_rsecs / $ncalls;
                 if ($rtotal) {
                     $pcnt = 100 * $rtimes[$j] / $rtotal;
                 } else {
                     $pcnt = 100;
                 }
             }
             if (array_key_exists('R', $opt)) {
                 $percall = $rsecs / $ncalls;
                 $cpercall = $c_rsecs / $ncalls;
                 if ($rtotal) {
                     $pcnt = 100 * $c_rtimes[$j] / $rtotal;
                 } else {
                     $pcnt = 100;
                 }
             }
             if (array_key_exists('u', $opt)) {
                 $percall = $usecs / $ncalls;
                 $cpercall = $c_usecs / $ncalls;
                 if ($utotal) {
                     $pcnt = 100 * $this->utimes[$j] / $utotal;
                 } else {
                     $pcnt = 100;
                 }
             }
             if (array_key_exists('U', $opt)) {
                 $percall = $usecs / $ncalls;
                 $cpercall = $c_usecs / $ncalls;
                 if ($utotal) {
                     $pcnt = 100 * $this->c_utimes[$j] / $utotal;
                 } else {
                     $pcnt = 100;
                 }
             }
             if (array_key_exists('s', $opt)) {
                 $percall = $ssecs / $ncalls;
                 $cpercall = $c_ssecs / $ncalls;
                 if ($stotal) {
                     $pcnt = 100 * $this->stimes[$j] / $stotal;
                 } else {
                     $pcnt = 100;
                 }
             }
             if (array_key_exists('S', $opt)) {
                 $percall = $ssecs / $ncalls;
                 $cpercall = $c_ssecs / $ncalls;
                 if ($stotal) {
                     $pcnt = 100 * $this->c_stimes[$j] / $stotal;
                 } else {
                     $pcnt = 100;
                 }
             }
             //        $cpercall = ($c_usecs + $c_ssecs)/$ncalls;
             $mem_usage = $this->mem[$j];
             $name = $symbol_hash[$j];
             $retstring .= sprintf("%3.01f %2.02f %2.02f  %2.02f %2.02f  %2.02f %2.02f  %4d  %2.04f   %2.04f %12d %s\n", $pcnt, $rsecs, $c_rsecs, $usecs, $c_usecs, $ssecs, $c_ssecs, $ncalls, $percall, $cpercall, $mem_usage, $name);
             return $retstring;
         }
     }
     return $retstring;
 }
Example #28
0
    echo $err_msg;
    exit(1);
}
if (!defined('SQ_SYSTEM_ROOT')) {
    define('SQ_SYSTEM_ROOT', $SYSTEM_ROOT);
}
require_once $SYSTEM_ROOT . '/core/include/init.inc';
// firstly let's check that we are OK for the version
if (version_compare(PHP_VERSION, SQ_REQUIRED_PHP_VERSION, '<')) {
    trigger_error('<i>' . SQ_SYSTEM_LONG_NAME . '</i> requires PHP Version ' . SQ_REQUIRED_PHP_VERSION . '.<br/> You may need to upgrade.<br/> Your current version is ' . PHP_VERSION, E_USER_ERROR);
}
// only use console stuff if we're running from the command line
require_once 'Console/Getopt.php';
$shortopt = '';
$longopt = array('package=');
$con = new Console_Getopt();
$args = $con->readPHPArgv();
array_shift($args);
$options = $con->getopt($args, $shortopt, $longopt);
if (is_array($options[0])) {
    $package_list = get_console_list($options[0]);
}
// check to see if the default/ tech email in main.inc are provided and are correct
// for more info see bug report 5804 Default and Tech Emails shouldnt break install
require_once SQ_FUDGE_PATH . '/general/www.inc';
$SQ_CONF_DEFAULT_EMAIL = SQ_CONF_DEFAULT_EMAIL;
if (!empty($SQ_CONF_DEFAULT_EMAIL) && !valid_email($SQ_CONF_DEFAULT_EMAIL)) {
    echo "Value '{$SQ_CONF_DEFAULT_EMAIL}' configued for 'SQ_CONF_DEFAULT_EMAIL' in main.inc is not valid.\nPlease fix it and try running the script again.\n";
    exit(1);
}
$SQ_CONF_TECH_EMAIL = SQ_CONF_TECH_EMAIL;
 if (!$config->validConfiguration()) {
     PEAR::raiseError('CRITICAL ERROR: no existing valid configuration files found in files ' . "'{$pear_user_config}' or '{$pear_system_config}', please copy an existing configuration" . 'file to one of these locations, or use the -c and -s options to create one');
 }
 PEAR::pushErrorHandling(PEAR_ERROR_RETURN);
 $cmd = PEAR_Command::factory($command, $config);
 PEAR::popErrorHandling();
 if (PEAR::isError($cmd)) {
     usage(null, @$options[1][0]);
 }
 $short_args = $long_args = null;
 PEAR_Command::getGetoptArgs($command, $short_args, $long_args);
 if (in_array('getopt2', get_class_methods('Console_Getopt'))) {
     array_shift($options[1]);
     $tmp = Console_Getopt::getopt2($options[1], $short_args, $long_args);
 } else {
     $tmp = Console_Getopt::getopt($options[1], $short_args, $long_args);
 }
 if (PEAR::isError($tmp)) {
     break;
 }
 list($tmpopt, $params) = $tmp;
 $opts = array();
 foreach ($tmpopt as $foo => $tmp2) {
     list($opt, $value) = $tmp2;
     if ($value === null) {
         $value = true;
         // options without args
     }
     if (strlen($opt) == 1) {
         $cmdoptions = $cmd->getOptions($command);
         foreach ($cmdoptions as $o => $d) {
Example #30
0
<?php

require_once 'Console/Getopt.php';
require_once 'DB.php';
function usage()
{
    die("php -q mysql2turbine.php");
}
$short = 'u:p:';
$result = Console_Getopt::getopt($argv, $short);
if (PEAR::isError($result)) {
    die($result->getMessage() . "\n");
}
list($args, $info) = $result;
$argList = array('u' => array('user', 'root'), 'p' => array('pass', ''));
$final = array();
while (list($arg, $defaults) = each($argList)) {
    for ($i = 0; $i < count($args); ++$i) {
        $var = $args[$i][0];
        $val = $args[$i][1];
        if ($arg == $var) {
            $final[$defaults[0]] = $val;
        }
    }
    if (!isset($final[$defaults[0]]) && empty($final[$defaults[0]])) {
        $final[$defaults[0]] = $defaults[1];
    }
}
$database = $info[0];
$tables = array();
for ($i = 1; $i < count($info); ++$i) {