Example #1
0
 public function __construct($workingDir = '.', $info, $commandsSeq = array())
 {
     parent::__construct($workingDir, $info, $commandsSeq);
     Console::initCore();
     $this->root_dir = Config::get('ROOT_DIR');
     $this->models_dir = Config::get('models_dir');
 }
Example #2
0
 function process()
 {
     Console::initCore();
     if (($c = ArgsHolder::get()->shiftCommand()) == 'help') {
         return $this->cmdHelp();
     }
     try {
         $format = "%-25s %s";
         IO::out("");
         $s = DB::query('SELECT * FROM ' . self::TABLE . ' where id="' . $c . '"');
         if (!count($s)) {
             io::out("Work with id={$c} is not exists", IO::MESSAGE_FAIL);
             return;
         }
         io::out(sprintf($format, "~CYAN~id~~~", $c));
         io::out(sprintf($format, "~CYAN~queue~~~", $this->emp($s[0]['queue'])));
         io::out(sprintf($format, "~CYAN~priority~~~", $this->emp($s[0]['priority'])));
         io::out(sprintf($format, "~CYAN~run at~~~", $this->emp($s[0]['run_at'])));
         io::out(sprintf($format, "~CYAN~locked at~~~", $this->emp($s[0]['locked_at'])));
         io::out(sprintf($format, "~CYAN~finished at~~~", $this->emp($s[0]['finished_at'])));
         io::out(sprintf($format, "~CYAN~failed at~~~", $this->emp($s[0]['failed_at'])));
         io::out(sprintf($format, "~CYAN~attemts~~~", $this->emp($s[0]['attempts'])));
         $handler = unserialize($s[0]["handler"]);
         io::out(sprintf($format, "~CYAN~call~~~", $handler["class"] . "::" . $handler["method"]) . "(...)");
         if (isset($handler["param"])) {
             io::out(sprintf($format, "~CYAN~params~~~", trim(self::walker($handler['param']), ',')));
         }
     } catch (Exception $e) {
         io::out($e->getMessage(), IO::MESSAGE_FAIL);
         return;
     }
     IO::out("");
 }
Example #3
0
 function process()
 {
     Console::initCore();
     if ($r = ArgsHolder::get()->getOption('count')) {
         $this->count = $r;
     }
     if (($c = ArgsHolder::get()->shiftCommand()) == 'help') {
         return $this->cmdHelp();
     }
     try {
         IO::out("");
         $sql = 'SELECT * FROM ' . self::TABLE . ' where not isnull(finished_at) and not 
             isnull(locked_at) and isnull(failed_at) ORDER BY run_at DESC';
         if ($this->count) {
             $list = DB::query($sql . ' LIMIT ' . $this->count);
         } else {
             $list = DB::query($sql);
         }
         if (!count($list)) {
             IO::out("No finished work!", IO::MESSAGE_FAIL);
             return;
         }
         io::out(sprintf("%-10s %-7s %-3s %-20s %-20s %-19s %-4s %-5s", "~CYAN~id", "queue", "pr", "run_at", "locked_at", "finished_at", "att", "call_to~~~"));
         foreach ($list as $l) {
             $handler = unserialize($l["handler"]);
             io::out(sprintf("%-4s %-7s %-3s %-20s %-20s %-20s %-3s %-5s", $l["id"], $l["queue"], $l["priority"], $l["run_at"], $l["locked_at"], $l["finished_at"], $l["attempts"], $handler["class"] . "::" . $handler["method"] . "(...)"));
         }
     } catch (Exception $e) {
         io::out($e->getMessage(), IO::MESSAGE_FAIL);
         return;
     }
     IO::out("");
 }
Example #4
0
 function process()
 {
     Console::initCore();
     if (($c = ArgsHolder::get()->shiftCommand()) == 'help') {
         return $this->cmdHelp();
     }
     try {
         if (is_numeric($c)) {
             $this->deleteById($c);
         } else {
             $this->deleteQueue($c);
         }
     } catch (Exception $e) {
         io::out($e->getMessage(), IO::MESSAGE_FAIL);
         return;
     }
 }
Example #5
0
 function process()
 {
     Console::initCore();
     if (($c = ArgsHolder::get()->shiftCommand()) == 'help') {
         return $this->cmdHelp();
     }
     try {
         if (is_numeric($c)) {
             $this->RestartById($c);
         } else {
             io::out("You can input only id of work.", IO::MESSAGE_FAIL);
         }
         return;
     } catch (Exception $e) {
         io::out($e->getMessage(), IO::MESSAGE_FAIL);
         return;
     }
 }
Example #6
0
<?php

Console::initCore();
class CmdEnv extends Command
{
    function CmdList()
    {
        io::out('~WHITE~Current env~~~: ' . ($env = EnvManager::getCurrent()));
        io::out();
        IO::OUt('~WHITE~Avaible enviroments:~~~');
        foreach (EnvManager::envList() as $e) {
            if ($e != $env) {
                io::out('    ' . $e);
            }
        }
    }
}
class EnvManager
{
    public static function getCurrent()
    {
        $file = file_get_contents(Config::get('ROOT_DIR') . '/config/config.ini');
        if (preg_match('#^\\s*\\[\\s*config\\s*:\\s*(\\S+)\\s*\\]\\s*$#m', $file, $m)) {
            return $m[1];
        }
        return false;
    }
    public static function envList()
    {
        if (preg_match_all('#^\\s*\\[\\s*(\\S+)\\s*:\\s*base\\s*\\]\\s*$#m', file_get_contents(Config::get('ROOT_DIR') . '/config/config.ini'), $m)) {
            return $m[1];
Example #7
0
 public function process()
 {
     Console::initCore();
     $this->separate = ArgsHolder::get()->getOption('separate');
     $this->all = ArgsHolder::get()->getOption('all');
     if ($r = ArgsHolder::get()->getOption('send-email')) {
         $this->send_email = true;
         $this->email_address = explode(",", $r);
         foreach ($this->email_address as $emails) {
             if (!preg_match(POSTChecker::$email_regexp, $emails)) {
                 io::out("Incorrect email address format", IO::MESSAGE_FAIL);
                 return;
             }
         }
     }
     try {
         $root = Config::get('ROOT_DIR');
         $name = basename($root);
         //Create MySQL dump
         $sqlname = $this->createMySQL($root, $name, $this->separate);
         //Create backup file
         $filename = $this->createTar($root, $name, $this->separate);
         if (!$this->separate) {
             unlink($root . '/' . $sqlname);
         }
         if ($this->send_email) {
             if (is_array($this->email_address)) {
                 $toout = implode(',', $this->email_address);
             } else {
                 $toout = $this->email_address;
             }
             io::out("Sending email to ~WHITE~" . $toout . '~~~', false);
             $a = Mail::CreateMail();
             foreach ($this->email_address as $emails) {
                 $a->toAdd($emails);
             }
             $a->setSubject("Backup " . $filename);
             $a->setFromname(Config::getInstance()->mail->default_from_name);
             $a->setFrom(Config::getInstance()->mail->default_from);
             $a->Message("Backup with filename " . $filename);
             $a->attachAdd($root . "/" . $filename);
             if ($this->separate) {
                 $a->attachAdd($root . "/" . $sqlname);
             }
             $r = $a->send();
             if ($r === false) {
                 io::out('', IO::MESSAGE_FAIL);
             } else {
                 io::done();
                 if (ArgsHolder::get()->getOption('clean')) {
                     IO::out('Cleaning ', false);
                     if ($this->separate) {
                         IO::out($sqlname . ' ', false);
                         unlink($root . '/' . $sqlname);
                     }
                     IO::out($filename . ' ', false);
                     unlink($root . '/' . $filename);
                     IO::done();
                 }
             }
         }
     } catch (Exception $e) {
         io::out($e->getMessage(), IO::MESSAGE_FAIL);
         return;
     }
 }
Example #8
0
 public function process()
 {
     Console::initCore();
     $version = array();
     exec('tidy -v 2>&1', $version, $ret);
     $version = implode("\n", $version);
     if ($ret != 0) {
         return io::out("You should install tidy to use converter. Exiting.") | 1;
     }
     $ah = ArgsHolder::get();
     $this->show_body_only = $ah->getOption('show-body-only');
     $this->tidy_only = $ah->getOption('tidy-only');
     if ($f = ArgsHolder::get()->getOption('output')) {
         $this->output_file = trim($f, "/");
     }
     if (($filename = ArgsHolder::get()->shiftCommand()) === false) {
         $this->cmdHelp();
         return io::out("Choose file to convert. Exiting.", IO::MESSAGE_FAIL) | 2;
     }
     if (!file_exists($filename)) {
         $filename = getcwd() . "/" . trim($filename, "/");
     }
     touch($filename);
     if (!file_exists($filename)) {
         return io::out("File " . $filename . " not found", IO::MESSAGE_FAIL) | 2;
     }
     if (!empty($this->output_file)) {
         if (dirname($this->output_file) == "") {
             $this->output_file = getcwd() . "/" . $this->output_file;
         }
         if (!is_dir(dirname($this->output_file))) {
             return io::out("Output direcotory doesn't exists", IO::MESSAGE_FAIL) | 4;
         }
         touch($this->output_file);
     }
     $output = $ret = null;
     exec("tidy -config " . escapeshellarg(dirname(__FILE__) . "/tidy.config") . " -q " . ($this->show_body_only ? " --show-body-only yes " : " ") . (" --error-file " . escapeshellarg(dirname(__FILE__)) . "/error.log ") . escapeshellarg($filename), $output, $ret);
     if ($ret == 0) {
         io::done('Tidy-ize done. ');
     } elseif ($ret == 1) {
         io::out('Tidy-ize done, but with warnings. (' . dirname(__FILE__) . "/error.log) ", IO::MESSAGE_WARN);
     } else {
         return io::out("Tidy-ize failed. ", IO::MESSAGE_FAIL) | 3;
     }
     if ($this->tidy_only) {
         if (!empty($this->output_file)) {
             io::out('Writing html to file ');
             $_r = file_put_contents($this->output_file, implode("\n", $output));
             if ($_r === false) {
                 return io::out("Can't write to file. May be permission denied? ", IO::MESSAGE_FAIL) | 5;
             }
             io::done();
         } else {
             echo implode("\n", $output) . "\n";
         }
         return 0;
     }
     $doc = new DOMDocument('1.0', 'utf-8');
     $doc->loadHTML(implode("\n", $output));
     $doc->encoding = "utf-8";
     $subst = array("a" => "WHyperLink", "td" => "WTableColumn", "tr" => "WTableRow", "th" => "WTableHeader", "table" => "WTable", "br" => "WText:br:1", "img" => "WImage", "abbr" => "WText:abbr:1", "acronym" => "WText:acronym:1", "address" => "WText:address:1", "b" => "WText:b:1", "big" => "WText:big:1", "blockquote" => "WText:blockquote:1", "button" => "WButton:type:button", "cite" => "WText:cite:1", "code" => "WText:code:1", "div" => "WBlock", "dfn" => "WText:dfn:1", "em" => "WText:em:1", "fieldset" => "WFieldSet", "form" => "WForm", "h1" => "WText:h:1", "h2" => "WText:h:2", "h3" => "WText:h:3", "h4" => "WText:h:4", "h5" => "WText:h:5", "h6" => "WText:h:6", "hr" => "WText:hr:1", "i" => "WText:i:1", "input" => "WEdit", "ins" => "WText:ins:1", "kbd" => "WText:kbd:1", "li" => "WListItem", "ol" => "WList:ol:1", "option" => "WSelectOption", "p" => "WText:p:1", "pre" => "WText:pre:1", "q" => "WText:q:1", "samp" => "WText:samp:1", "script" => "WInlineScript", "select" => "WSelect", "small" => "WText:small:1", "span" => "WText", "strike" => "WText:strike:1", "strong" => "WText:strong:1", "style" => "WCSS", "sub" => "WText:sub:1", "sup" => "WText:sup:1", "textarea" => "WTextarea", "ul" => "WList", "var" => "WText:var:1", "body" => "root");
     foreach ($subst as $replace_from => $replace_to) {
         @(list($replace_to, $new_attr_name, $new_attr_value) = explode(":", $replace_to));
         $nl = $doc->getElementsByTagName($replace_from);
         for ($i = 0, $c = $nl->length; $i < $c; $i++) {
             $n_dn = $doc->createElement($replace_to);
             $cn = $nl->item(0);
             $cnl = $cn->childNodes;
             if ($cn->hasAttributes()) {
                 foreach ($cn->attributes as $attrName => $attrNode) {
                     if (substr((string) $attrNode->value, 0, 2) != "__" && !empty($attrNode->value)) {
                         $n_dn->setAttribute((string) $attrName, $attrNode->value);
                     }
                 }
             }
             if (isset($new_attr_value, $new_attr_name)) {
                 $n_dn->setAttribute($new_attr_name, $new_attr_value);
             }
             for ($j = 0; $j < $cnl->length; $j++) {
                 if ($cnl->item($j) instanceof DOMText) {
                     $n_dn->appendChild($doc->createTextNode($cnl->item($j)->nodeValue));
                 } else {
                     $n_dn->appendChild($cnl->item($j)->cloneNode(true));
                 }
             }
             $cn->parentNode->replaceChild($n_dn, $cn);
         }
     }
     io::out('Dumping XML...', false);
     if ($this->show_body_only) {
         if (!empty($this->output_file)) {
             file_put_contents($this->output_file, utf8_decode($doc->saveXML($doc->getElementsByTagName("root")->item(0))));
         } else {
             echo utf8_decode($doc->saveXML($doc->getElementsByTagName("root")->item(0)));
         }
     } else {
         if (!empty($this->output_file)) {
             $doc->save($this->output_file);
         } else {
             echo $doc->saveXML();
         }
     }
     io::done();
 }