public function cmd_list() { \System\Init::basic(); $list = cfg('assets', 'dependencies'); if ($this->json) { \Helper\Cli::out(json_encode(array("dependencies" => $list), JSON_PRETTY_PRINT)); } else { \Helper\Cli::out('Bower dependencies'); \Helper\Cli::out_flist(array("list" => $list, "margin" => 2)); } }
public static function cmd_all() { \System\Init::basic(); $all = self::get_all(); $path = \System\Composer::resolve('/etc/init.d/test.php'); foreach ($all as $key => $val) { $cmd = implode(';', array("cd '" . BASE_DIR . "'", "phpunit --bootstrap '" . $path . "' --colors --test-suffix .php '" . $val . "'")); \Helper\Cli::out($val); $out = passthru($cmd); \Helper\Cli::out(); } }
/** * Build static cache * * @return void */ public function cmd_static() { \System\Init::basic(); $lib_list = \System\Composer::get_libs(); $libs = array(); foreach ($lib_list as $lib) { $libs[$lib] = $lib; } array_push($libs, null); \Helper\Cli::do_over($libs, function ($key, $name) { \System\Cache::build_static_for($name); }, 'Collecting static files'); }
public function cmd_workshops() { \System\Init::full(); $ws = \Workshop::get_all()->fetch(); $dump = array(); foreach ($ws as $workshop) { $signups = $workshop->assignees->where(array("solved" => true))->fetch(); array_push($dump, $workshop->name, "------\n"); foreach ($signups as $signup) { array_push($dump, $signup->toName() . ': ' . $signup->email . ' ' . $signup->phone); } array_push($dump, "\n"); } echo implode("\n", $dump); }
/** Initialize all scripts for this request and domain * @return void */ public function init() { if ($this->get('lang')) { $this->lang = $this->get('lang'); } else { if ($this->cookie('lang')) { $this->lang = $this->cookie('lang'); } } try { $login = \System\Settings::get('policies', 'auto_login'); } catch (\System\Error\Config $e) { $login = true; } if ($login) { $this->relogin(); } \System\Init::run($this->init, array("request" => $this)); return $this; }
public function cmd_pair() { \System\Init::full(); $token = \System\Settings::get('bank', 'token'); $from = \System\Settings::get('bank', 'from'); $to = date('Y-m-d'); $url = str_replace('{token}', $token, self::URL_TRANSACTIONS); $url = str_replace('{from}', $from, $url); $url = str_replace('{to}', $to, $url); $res = \Helper\Offcom\Request::get($url); if (!$res->ok()) { if ($res->status == 409) { \Helper\Cli::out('Please wait 30 seconds and try again.'); exit(4); } else { \Helper\Cli::out('Unknown error during transaction scrape.'); exit(5); } } $feed = \System\Json::decode($res->content); \Workshop\Payment::pair_with_feed($feed); }
public static function cmd_database() { \System\Init::full(); $db_list = \System\Settings::get('database', 'list'); foreach ($db_list as $db_ident => $db_cfg) { $size = \System\Database::query("\n\t\t\t\t\tSELECT\n\t\t\t\t\t\t\tsum(data_length + index_length) 'size',\n\t\t\t\t\t\t\tsum( data_free ) 'free'\n\t\t\t\t\t\tFROM information_schema.TABLES\n\t\t\t\t\t\tWHERE table_schema = '" . $db_cfg['database'] . "'\n\t\t\t\t\t\tGROUP BY table_schema;\n\t\t\t\t")->fetch(); $mlast_date = false; $mcount = 0; try { $mig = \System\Database\Migration::get_new(); $mcount = count($mig); $stat = "Ok"; $mlast = \System\Database\Migration::get_first()->where(array("status" => 'ok'))->sort_by("updated_at DESC")->fetch(); if ($mlast) { $mlast_date = $mlast->updated_at; } } catch (System\Error $e) { $stat = "Migrating database is necessary."; } \Helper\Cli::out('Database ' . $db_ident); \Helper\Cli::sep(); \Helper\Cli::out_flist(array("list" => array("Driver" => $db_cfg['driver'], "Host name" => $db_cfg['host'], "Database name" => $db_cfg['database'], "User" => $db_cfg['username'], "Used charset" => $db_cfg['charset'], "Lazy driver" => $db_cfg['lazy'] ? 'yes' : 'no', "Size" => \System\Template::convert_value('information', $size['size']), "Free space" => \System\Template::convert_value('information', $size['free']), "Structure" => $stat, "Last migrated" => $mlast_date ? $mlast_date->format('Y-m-d H:i:s') : 'never', "New migrations" => $mcount))); } }
public function cmd_lostAndFound() { \System\Init::full(); $users = \Workshop\SignUp::get_all()->where(array("solved" => true, "newsletter" => true, "sentLostAndFound" => false))->fetch(); \Helper\Cli::do_over($users, function ($key, $user) { $ren = new \System\Template\Renderer\Txt(); $ren->reset_layout(); $ren->partial('mail/notif/lost-and-found', array("user" => $user, "symvar" => $user->check->symvar)); $mail = new \Helper\Offcom\Mail(array('rcpt' => array($user->email), 'subject' => 'Improtřesk 2016 - Ztráty a nálezy, pozvánka', 'reply_to' => \System\Settings::get('offcom', 'default', 'reply_to'), 'message' => $ren->render_content())); $mail->send(); $user->sentLostAndFound = true; $user->save(); }); }
private static function seed_data($data_set_name, $data_set_models) { \System\Init::full(); foreach ($data_set_models as $model => $data_set) { $extra = array("model" => $model); \Helper\Cli::do_over($data_set, function ($key, $tdata, $extra) { $model = $extra['model']; $obj = null; $idc = $model::get_id_col($model); if (isset($tdata[$col = 'id']) || isset($tdata[$col = $idc])) { $tdata[$idc] = $tdata[$col]; $obj = $model::find($tdata[$col]); } if ($obj) { $obj->update_attrs($tdata); } else { $obj = new $model($tdata); $obj->is_new_object = true; } $obj->save(); foreach ($tdata as $attr => $val) { if (is_array($val) && $model::is_rel($attr)) { if ($model::get_attr_type($attr) == $model::REL_HAS_MANY) { $def = $model::get_attr($attr); if (any($def['is_bilinear']) && any($def['is_master'])) { unset($obj->{$attr}); $obj->{$attr} = $val; } } } } }, $data_set_name . ': ' . \System\Loader::get_model_from_class($model), $extra); } }
public function init() { if (!$this->is_initialized()) { $this->cookie_store('lang', $this->locales->get_lang()); if ($this->init) { \System\Init::run($this->init, array("request" => $this->request, "response" => $this)); } $this->init_done = true; } }