Esempio n. 1
0
}
function infoCountEmpty($table, $field, $nonEmpty = false)
{
    $sql = "SELECT COUNT(*) FROM {$table}";
    if ($nonEmpty) {
        $sql .= " WHERE {$field} IS NOT NULL OR {$field} != ''";
        $negation = ' non';
    } else {
        $sql .= " WHERE {$field} IS NULL OR {$field} = ''";
        $negation = '';
    }
    $comment = "Nombre de champs '{$field}'{$negation} vides dans la table '{$table}'.";
    info($sql, $comment, true);
}
/* Parses options. */
$opts = Console_GetOpt::getopt($argv, 'v');
$opt_verbose = false;
if (PEAR::isError($opts)) {
    echo $opts->getMessage();
} else {
    $opts = $opts[0];
    foreach ($opts as $opt) {
        switch ($opt[0]) {
            case 'v':
                $opt_verbose = true;
                break;
        }
    }
}
/* Checks rewriting on deleted aliases. */
check("SELECT  s1.email, r.redirect, r.rewrite AS broken\n         FROM  email_redirect_account AS r\n   INNER JOIN  email_source_account   AS s1 ON (r.uid = s1.uid AND s1.type = 'forlife')\n    LEFT JOIN  email_source_account   AS s2 ON (r.uid = s2.uid AND r.rewrite LIKE CONCAT(s2.email, '@%'))\n        WHERE  r.rewrite != '' AND s2.uid IS NULL", "Personnes qui ont des rewrite sur un alias perdu.");
Esempio n. 2
0
 /**
  * Run the CLI task, which will check which command is specified and run it.
  */
 public static function run()
 {
     CLI::taskName("help");
     CLI::taskRun(array('self', 'help'));
     global $argv;
     $args = $argv;
     $cliname = array_shift($args);
     $taskName = array_shift($args);
     while ($taskName[0] == '-') {
         $taskName = array_shift($args);
     }
     if (!$taskName) {
         echo self::error("Specify a task from the list below.") . "\n\n";
         self::help(null, null);
         return;
     }
     $taskData = null;
     foreach (self::$tasks as $name => $data) {
         if (strcasecmp($name, $taskName) === 0) {
             $taskData = $data;
             break;
         }
     }
     if (!$taskData) {
         echo self::error("Command not found: '{$taskName}'") . "\n\n";
         self::help(null, null);
         return;
     }
     G::LoadThirdParty('pear/Console', 'Getopt');
     $short = "h" . $taskData['opt']['short'];
     $long = array_merge(array("help"), $taskData['opt']['long']);
     $getopt = Console_GetOpt::getopt2($args, $short, $long);
     if (!is_array($getopt)) {
         echo self::error("Invalid options (" . $getopt->getMessage() . ")") . "\n\n";
         self::help($taskName);
         return;
     }
     list($options, $arguments) = $getopt;
     foreach ($taskData['opt']['descriptions'] as $optName => $optDescription) {
         $short = str_replace(":", "", $optDescription['short']);
         $long = str_replace("=", "", $optDescription['long']);
         $validOpts[$short] = $optName;
         $validOpts[$long] = $optName;
     }
     $taskOpts = array();
     try {
         foreach ($options as $opt) {
             list($optName, $optArg) = $opt;
             if ($optName === "h" || $optName === "--help") {
                 self::help($taskName);
                 return;
             }
             if (strpos($optName, '--') === 0) {
                 $optName = substr($optName, 2);
             }
             if (!array_key_exists($optName, $validOpts)) {
                 throw new Exception("option not found: {$optName}");
             }
             if (array_key_exists($validOpts[$optName], $taskOpts)) {
                 throw new Exception("'{$optName}' specified more then once");
             }
             $taskOpts[$validOpts[$optName]] = $optArg;
         }
     } catch (Exception $e) {
         echo self::error("Invalid options: " . $e->getMessage()) . "\n\n";
         self::help($taskName);
         return;
     }
     try {
         call_user_func($taskData['function'], $arguments, $taskOpts);
     } catch (Exception $e) {
         echo self::error("\n  Error executing '{$taskName}':\n\n  {$e->getMessage()}\n") . "\n";
     }
 }
 /**
  *  (experimental)
  *  @return array
  */
 function _getPearOpt(&$cmd_obj, $cmd_str, $opt_array)
 {
     $short_args = $long_args = null;
     PEAR_Command::getGetOptArgs($cmd_str, $short_args, $long_args);
     $opt_arg = Console_GetOpt::getOpt2($opt_array, $short_args, $long_args);
     if (PEAR::isError($opt_arg)) {
         return array();
     }
     $opts = array();
     foreach ($opt_arg[0] as $tmp) {
         list($opt, $val) = $tmp;
         if ($val === null) {
             $val = true;
         }
         if (strlen($opt) == 1) {
             $cmd_opts = $cmd_obj->getOptions($cmd_str);
             foreach ($cmd_opts as $o => $d) {
                 if (isset($d['shortopt']) && $d['shortopt'] == $opt) {
                     $opts[$o] = $value;
                 }
             }
         } else {
             if (substr($opt, 0, 2) == '--') {
                 $opts[substr($opt, 2)] = $value;
             }
         }
     }
     return $opts;
 }