#!/usr/bin/php <?php error_reporting(E_ALL ^ E_NOTICE ^ E_WARNING); if (!isset($_SERVER['argc'])) { exit; } include __DIR__ . '/../lib/l.env.php'; include __DIR__ . '/osy.data.align.php'; define("CRON_LIB_EXT", __DIR__ . '/../../../../../lib/'); env::init(false); env::$iid = "default"; class osycron { public static function exec_script($app, $cid, $cod) { env::$dba = env::dbcon_by_app($app); $msg = ($f = @create_function('', $cod)) ? $f() : print_r(error_get_last(), true); //update last execution env::$dbo->exec_cmd("INSERT INTO osy_obj_prp (o_id,p_id,p_ord,p_vl)\n VALUES\n (?,'exec-last-date',10,NOW())\n ON DUPLICATE KEY UPDATE p_vl = NOW();", array($cid)); //update last message env::$dbo->exec_cmd("INSERT INTO osy_obj_prp (o_id,p_id,p_ord,p_vl)\n VALUES\n (?,'exec-last-message',10,?)\n ON DUPLICATE KEY UPDATE p_vl = ?;", array($cid, $msg, $msg)); return $msg; } public static function init() { $strSQL = "SELECT a.app_id,\n a.str_cn,\n a.crn_id,\n a.cod\n FROM ( \n SELECT a.app_id,\n a.crn_id,\n a.str_cn,\n a.cod,\n tim_to_exe,\n UNIX_TIMESTAMP(NOW()) AS _now,\n UNIX_TIMESTAMP(a.exe_lst) AS lst,\n CASE \n WHEN a.tim_to_exe > UNIX_TIMESTAMP(NOW()) THEN 0\n WHEN a.tim_to_exe < UNIX_TIMESTAMP(a.exe_lst) THEN 0\n ELSE 1\n END AS exe\n FROM (\n SELECT distinct\n i.p_1 as str_cn,\n cr.o_own AS app_id,\n \n cr.o_id AS crn_id,\n cd.p_vl AS cod,\n UNIX_TIMESTAMP(STR_TO_DATE(CONCAT( IF(py.p_vl = '*',YEAR(NOW()),py.p_vl) , \n '-',\n IF(pm.p_vl = '*',MONTH(NOW()),pm.p_vl) , \n '-',\n IF(pd.p_vl = '*',DAY(NOW()),pd.p_vl) , \n ' ',\n IF(ph.p_vl = '*',HOUR(NOW()),ph.p_vl),\n ':',\n IF(pmi.p_vl = '*',MINUTE(NOW()),pmi.p_vl),\n ':',\n IF(ps.p_vl = '*',MINUTE(NOW()),ps.p_vl)),'%Y-%m-%d %H:%i:%s')) AS tim_to_exe,\n IFNULL(lex.p_vl,0) AS exe_lst\n FROM osy_obj cr\n INNER JOIN osy_obj_rel i ON (cr.o_own = i.o_2 AND i.r_typ = 'instance+application')\n INNER JOIN osy_obj_prp cd ON (cr.o_id = cd.o_id AND cd.p_id = 'code')\n INNER JOIN osy_obj_prp act ON (cr.o_id = act.o_id AND act.p_id = 'is-active')\n LEFT JOIN osy_obj_prp py ON (cr.o_id = py.o_id AND py.p_id = 'exec-year')\n LEFT JOIN osy_obj_prp pm ON (cr.o_id = pm.o_id AND pm.p_id = 'exec-month')\n LEFT JOIN osy_obj_prp pd ON (cr.o_id = pd.o_id AND pd.p_id = 'exec-day')\n LEFT JOIN osy_obj_prp ph ON (cr.o_id = ph.o_id AND ph.p_id = 'exec-hour')\n LEFT JOIN osy_obj_prp pmi ON (cr.o_id = pmi.o_id AND pmi.p_id = 'exec-minute')\n LEFT JOIN osy_obj_prp ps ON (cr.o_id = ps.o_id AND ps.p_id = 'exec-second')\n LEFT JOIN osy_obj_prp lex ON (cr.o_id = lex.o_id AND lex.p_id = 'exec-last-date')\n WHERE cr.o_typ = 'cron' AND act.p_vl = '1'\n ) a\n ) a\n WHERE a.exe = 1"; $res = env::$dbo->exec_query($strSQL); if (is_array($res)) { foreach ($res as $script) { self::exec_script($script['app_id'], $script['crn_id'], $script['cod']); }
try { $options = getopt('vr:c:'); if (!empty($options['c']) && file_exists($options['c'])) { env::$ENV_CFG_FILE = $options['c']; } elseif (file_exists(__DIR__ . '/tubecacher.cfg')) { env::$ENV_CFG_FILE = __DIR__ . '/tubecacher.cfg'; } else { env::$ENV_CFG_FILE = __DIR__ . '/../tubecacher.cfg'; } env::$ENV_VERBOSE = isset($options['v']); if (isset($options['r'])) { env::$ENV_ITEMS_ROOT = realpath($options['r']); } _info('Config file: ' . realpath(env::$ENV_CFG_FILE)); _info('Items root: ' . env::$ENV_ITEMS_ROOT); $env = env::init(); _info('Looking for meta-files in ' . env::$ENV_ITEMS_ROOT); $meta = tubeAPI::getInstance()->searchMeta(); _echo(' > Found ' . count($meta) . ' playlists.'); foreach ($meta as $path) { $info = parse_ini_file($path, false, INI_SCANNER_RAW); if (empty($info['type'])) { continue; } switch ($info['type']) { case 'playlist': _info('Process playlist in `' . dirname($path) . '`'); if (empty($info['id'])) { _echo(' > No playlist ID specified. Skipping'); continue; }