diff --git a/lib/RippingCluster/BackgroundTask.class.php b/lib/RippingCluster/BackgroundTask.class.php deleted file mode 100644 index 54b3a7f..0000000 --- a/lib/RippingCluster/BackgroundTask.class.php +++ /dev/null @@ -1,17 +0,0 @@ - diff --git a/lib/RippingCluster/Cache.class.php b/lib/RippingCluster/Cache.class.php deleted file mode 100644 index d6f92ac..0000000 --- a/lib/RippingCluster/Cache.class.php +++ /dev/null @@ -1,62 +0,0 @@ -config = $config; - $this->cache_dir = $config->get('cache.base_dir'); - - if (is_dir($this->cache_dir)) { - if ( ! is_writeable($this->cache_dir)) { - throw new RippingCluster_Exception_InvalidCacheDir(); - } - } else { - if ( ! RippingCluster_Main::mkdir_recursive($this->cache_dir)) { - throw new RippingCluster_Exception_InvalidCacheDir(); - } - } - } - - protected function cacheFilename($source_filename) { - return $this->cache_dir . sha1($source_filename); - } - - public function exists($source_filename, $ttl = 3600) { - $cache_filename = $this->cacheFilename($source_filename); - - // Check to see if the file is cached - if (!file_exists($cache_filename)) { - return false; - } - - // Check to see if the cache has expired - if (filemtime($cache_filename) + $ttl < time()) { - // Delete the cached item - unlink($cache_filename); - return false; - } - - return true; - } - - public function store($source_filename, $content) { - $cache_filename = $this->cacheFilename($source_filename); - return file_put_contents($cache_filename, $content); - } - - public function fetch($source_filename, $ttl = 3600) { - $cache_filename = $this->cacheFilename($source_filename); - - if (!$this->exists($source_filename)) { - throw new RippingCluster_Exception_CacheObjectNotFound($source_filename); - } - - return file_get_contents($cache_filename); - } - -}; - -?> \ No newline at end of file diff --git a/lib/RippingCluster/ClientLogEntry.class.php b/lib/RippingCluster/ClientLogEntry.class.php deleted file mode 100644 index e471e80..0000000 --- a/lib/RippingCluster/ClientLogEntry.class.php +++ /dev/null @@ -1,13 +0,0 @@ - diff --git a/lib/RippingCluster/Config.class.php b/lib/RippingCluster/Config.class.php deleted file mode 100644 index 66785a5..0000000 --- a/lib/RippingCluster/Config.class.php +++ /dev/null @@ -1,145 +0,0 @@ -string) - */ - private $databaseConfig = array(); - - /** - * Associative array of settings loaded from the database - * @var array(string=>array(string=>string)) - */ - private $settings = array(); - - /** - * Constructs a new instance of the Config class - * - * @param string $dbconfig Database configuration file contents - * @return RippingCluster_Config - */ - public function __construct($dbconfig) { - $this->dbconfig = $dbconfig; - - $this->parseDatabaseConfig(); - } - - /** - * Parses the contents of the database configuration file so that individual settings can be retrieved. - * - */ - public function parseDatabaseConfig() { - $this->databaseConfig = parse_ini_file($this->dbconfig); - } - - /** - * Returns the value of the named item from the database configuration file - * - * @param string $key Name of the setting to retrieve - */ - public function getDatabase($key) { - if (!isset($this->databaseConfig[$key])) { - throw new RippingCluster_Exception_DatabaseConfigMissing($key); - } - - return $this->databaseConfig[$key]; - } - - /** - * Sets the database instance used by this object - * - * @param RippingCluster_Database $database Database instance - */ - public function setDatabase(RippingCluster_Database $database) { - $this->database = $database; - $this->preload(); - } - - /** - * Loads the entire list of settings from the database - * - */ - private function preload() { - if (!$this->database) { - throw new RippingCluster_Exception_NoDatabaseConnection(); - } - - $this->settings = $this->database->selectAssoc('SELECT name,type,value FROM settings', 'name', array('name', 'value', 'type')); - } - - /** - * Identifies whether the named setting exists - * - * @param string $key Name of the setting - * @return bool - */ - public function exists($key) { - return isset($this->settings[$key]); - } - - /** - * Fetches the value of the named setting - * - * @param string $key Name of the setting - */ - public function get($key) { - if (!isset($this->settings[$key])) { - throw new RippingCluster_Exception_UnknownSetting($key); - } - - switch ($this->settings[$key]['type']) { - case self::TYPE_STRING_LIST: - return array_map('trim', explode("\n", $this->settings[$key]['value'])); - - default: - return $this->settings[$key]['value']; - } - } - -}; - -?> diff --git a/lib/RippingCluster/Database.class.php b/lib/RippingCluster/Database.class.php deleted file mode 100644 index c42f162..0000000 --- a/lib/RippingCluster/Database.class.php +++ /dev/null @@ -1,141 +0,0 @@ -config = $config; - - $this->hostname = $this->config->getDatabase('hostname'); - $this->username = $this->config->getDatabase('username'); - $this->password = $this->config->getDatabase('password'); - $this->dbname = $this->config->getDatabase('dbname'); - - try { - $this->dbh = new PDO("mysql:host={$this->hostname};dbname={$this->dbname}", $this->username, $this->password); - } catch (PDOException $e) { - throw new RippingCluster_Exception_DatabaseConnectFailed($e->getMessage()); - } - - } - - public function __destruct() { - $this->dbh = null; - } - - public function selectAssoc($sql, $key_col, $value_cols) { - $results = array(); - - foreach ($this->dbh->query($sql) as $row) { - if (is_array($value_cols)) { - $values = array(); - foreach ($value_cols as $value_col) { - $values[$value_col] = $row[$value_col]; - } - - $results[$row[$key_col]] = $values; - } else { - $results[$row[$key_col]] = $row[$value_col]; - } - } - - return $results; - } - - public function selectList($sql, $bind_params = null) { - if ($bind_params) { - $stmt = $this->dbh->prepare($sql); - - foreach ($bind_params as $param) { - $stmt->bindValue(':'.$param['name'], $param['value'], $param['type']); - } - - $result = $stmt->execute(); - if (!$result) { - list($dummy, $code, $message) = $stmt->errorInfo(); - throw new RippingCluster_Exception_DatabaseQueryFailed($message, $code); - } - - return $stmt->fetchAll(); - - } else { - $results = array(); - - $result = $this->dbh->query($sql); - foreach ($result as $row) { - $results[] = $row; - } - - return $results; - } - } - - public function selectOne($sql, $bind_params = null) { - $rows = $this->selectList($sql, $bind_params); - if (count($rows) != 1) { - throw new RippingCluster_Exception_ResultCountMismatch(count($rows)); - } - - return $rows[0]; - } - - public function insert($sql, $bind_params = null) { - $stmt = $this->dbh->prepare($sql); - - if ($bind_params) { - foreach ($bind_params as $param) { - if (isset($param['type'])) { - $stmt->bindValue(':'.$param['name'], $param['value'], $param['type']); - } else { - $stmt->bindValue(':'.$param['name'], $param['value']); - } - } - } - - $result = $stmt->execute(); - if (!$result) { - list($code, $dummy, $message) = $stmt->errorInfo(); - throw new RippingCluster_Exception_DatabaseQueryFailed($message, $code); - } - } - - public function update($sql, $bind_params = null) { - $stmt = $this->dbh->prepare($sql); - - if ($bind_params) { - foreach ($bind_params as $param) { - if (isset($param['type'])) { - $stmt->bindValue(':'.$param['name'], $param['value'], $param['type']); - } else { - $stmt->bindValue(':'.$param['name'], $param['value']); - } - } - } - - $result = $stmt->execute(); - if (!$result) { - list($code, $dummy, $message) = $stmt->errorInfo(); - throw new RippingCluster_Exception_DatabaseQueryFailed($message, $code); - } - } - - public function errorInfo() { - return $this->dbh->errorInfo(); - } - - public function lastInsertId() { - return $this->dbh->lastInsertId(); - } - -} - -?> diff --git a/lib/RippingCluster/ForegroundTask.class.php b/lib/RippingCluster/ForegroundTask.class.php deleted file mode 100644 index 059a707..0000000 --- a/lib/RippingCluster/ForegroundTask.class.php +++ /dev/null @@ -1,113 +0,0 @@ - array('pipe', 'r'), - self::PIPE_STDOUT => array('pipe', 'w'), - self::PIPE_STDERR => array('pipe', 'w'), - ); - - $pipes = array(); - $process = proc_open($command, $descriptors, $pipes); - - stream_set_blocking($pipes[self::PIPE_STDIN], 0); // Make stdin/stdout/stderr non-blocking - stream_set_blocking($pipes[self::PIPE_STDOUT], 0); - stream_set_blocking($pipes[self::PIPE_STDERR], 0); - - if ($txLen == 0) { - fclose($pipes[0]); - } - - while (true) { - $rx = array(); // The program's stdout/stderr - if (!$stdoutDone) { - $rx[] = $pipes[self::PIPE_STDOUT]; - } - if (!$stderrDone) { - $rx[] = $pipes[self::PIPE_STDERR]; - } - - $tx = array(); // The program's stdin - if ($txOff < $txLen) { - $tx[] = $pipes[self::PIPE_STDIN]; - } - - $ex = array(); - - stream_select($rx, $tx, $ex, null, null); // Block til r/w possible - if (!empty($tx)) { - $txRet = fwrite($pipes[self::PIPE_STDIN], substr($stdin, $txOff, 8192)); - if ($txRet !== false) { - $txOff += $txRet; - } - if ($txOff >= $txLen) { - fclose($pipes[self::PIPE_STDIN]); - } - } - - foreach ($rx as $r) { - if ($r == $pipes[self::PIPE_STDOUT]) { - $chunk = fread($pipes[self::PIPE_STDOUT], 8192); - if (feof($pipes[self::PIPE_STDOUT])) { - fclose($pipes[self::PIPE_STDOUT]); $stdoutDone = true; - } - - if ($callback_stdout) { - call_user_func($callback_stdout, $identifier, $chunk); - } else { - $stdout .= $chunk; - } - - } else if ($r == $pipes[self::PIPE_STDERR]) { - $chunk = fread($pipes[self::PIPE_STDERR], 8192); - if (feof($pipes[self::PIPE_STDERR])) { - fclose($pipes[self::PIPE_STDERR]); $stderrDone = true; - } - - if ($callback_stderr) { - call_user_func($callback_stderr, $identifier, $chunk); - } else { - $stderr .= $chunk; - } - } - } - - if (!is_resource($process)) - break; - - if ($txOff >= $txLen && $stdoutDone && $stderrDone) - break; - } - - return array(proc_close($process), $stdout, $stderr); - } - -} - diff --git a/lib/RippingCluster/IPlugin.class.php b/lib/RippingCluster/IPlugin.class.php deleted file mode 100644 index 35cd7f4..0000000 --- a/lib/RippingCluster/IPlugin.class.php +++ /dev/null @@ -1,11 +0,0 @@ - \ No newline at end of file diff --git a/lib/RippingCluster/IPluginFactory.class.php b/lib/RippingCluster/IPluginFactory.class.php deleted file mode 100644 index 94c4aa6..0000000 --- a/lib/RippingCluster/IPluginFactory.class.php +++ /dev/null @@ -1,9 +0,0 @@ - \ No newline at end of file diff --git a/lib/RippingCluster/Log.class.php b/lib/RippingCluster/Log.class.php deleted file mode 100644 index db62519..0000000 --- a/lib/RippingCluster/Log.class.php +++ /dev/null @@ -1,61 +0,0 @@ -database = $database; - $this->config = $config; - $this->table = $table; - - } - - public function log($severity, $message, $job_id = 0) { - $this->database->insert("INSERT INTO {$this->table} (job_id,level,ctime,pid,hostname,progname,line,message) VALUES(:job_id, :level, :ctime, :pid, :hostname, :progname, :line, :message)", - array( - array('name' => 'job_id', 'value' => $job_id, 'type' => PDO::PARAM_INT), - array('name' => 'level', 'value' => $severity, 'type' => PDO::PARAM_STR), - array('name' => 'ctime', 'value' => time(), 'type' => PDO::PARAM_INT), - array('name' => 'pid', 'value' => 0, 'type' => PDO::PARAM_INT), - array('name' => 'hostname', 'value' => self::$hostname, 'type' => PDO::PARAM_STR), - array('name' => 'progname', 'value' => 'webui', 'type' => PDO::PARAM_STR), - array('name' => 'line', 'value' => 0, 'type' => PDO::PARAM_INT), - array('name' => 'message', 'value' => $message, 'type' => PDO::PARAM_STR) - ) - ); - - if (HBC_File == 'worker') { - echo date("r") . ' ' . $message . "\n"; - } - } - - public function debug($message, $job_id = 0) { - return $this->log('DEBUG', $message, $job_id); - } - - public function info($message, $job_id = 0) { - return $this->log('INFO', $message, $job_id); - } - - public function warning($message, $job_id = 0) { - return $this->log('WARNING', $message, $job_id); - } - - public function error($message, $job_id = 0) { - return $this->log('ERROR', $message, $job_id); - } - - public static function initialise() { - self::$hostname = trim(`hostname`); - } - -} - -RippingCluster_Log::initialise(); - -?> diff --git a/lib/RippingCluster/LogEntry.class.php b/lib/RippingCluster/LogEntry.class.php deleted file mode 100644 index 75ebd22..0000000 --- a/lib/RippingCluster/LogEntry.class.php +++ /dev/null @@ -1,122 +0,0 @@ -id = $id; - $this->job_id = $job_id; - $this->level = $level; - $this->ctime = $ctime; - $this->pid = $pid; - $this->hostname = $hostname; - $this->progname = $progname; - $this->line = $line; - $this->message = $message; - } - - public static function fromDatabaseRow($row) { - return new RippingCluster_ClientLogEntry( - $row['id'], - $row['job_id'], - $row['level'], - $row['ctime'], - $row['pid'], - $row['hostname'], - $row['progname'], - $row['line'], - $row['message'] - ); - } - - public static function fromId($id) { - $database = RippingCluster_Main::instance()->database(); - return RippingCluster_ClientLogEntry::fromDatabaseRow( - $database->selectOne('SELECT * FROM '.self::$table_name.' WHERE id=:id', array( - array('name' => 'id', 'value' => $id, 'type' => PDO::PARAM_INT) - ) - ) - ); - } - - public static function recent($limit = 100) { - $entries = array(); - - $database = RippingCluster_Main::instance()->database(); - foreach ($database->selectList('SELECT * FROM '.self::$table_name.' ORDER BY ctime DESC LIMIT :limit', array( - array('name' => 'limit', 'value' => $limit, 'type' => PDO::PARAM_INT) - )) as $row) { - $entries[] = self::fromDatabaseRow($row); - } - - return $entries; - } - - public static function recentForJob($job_id, $limit = 100) { - $entries = array(); - - $database = RippingCluster_Main::instance()->database(); - foreach ($database->selectList('SELECT * FROM '.self::$table_name.' WHERE job_id=:job_id ORDER BY ctime DESC LIMIT :limit', array( - array('name' => 'job_id', 'value' => $job_id, 'type' => PDO::PARAM_INT), - array('name' => 'limit', 'value' => $limit, 'type' => PDO::PARAM_INT) - )) as $row) { - $entries[] = self::fromDatabaseRow($row); - } - - return $entries; - } - - public static function allForNoJob() { - return self::allForJob(0); - } - - public function id() { - return $this->id; - } - - public function jobId() { - return $this->job_id; - } - - public function level() { - return $this->level; - } - - public function ctime() { - return $this->ctime; - } - - public function pid() { - return $this->pid; - } - - public function hostname() { - return $this->hostname; - } - - public function progname() { - return $this->progname; - } - - public function line() { - return $this->line; - } - - public function message() { - return $this->message; - } - -}; - -?> diff --git a/lib/RippingCluster/Main.class.php b/lib/RippingCluster/Main.class.php deleted file mode 100644 index d038e6b..0000000 --- a/lib/RippingCluster/Main.class.php +++ /dev/null @@ -1,230 +0,0 @@ -config = new RippingCluster_Config(RippingCluster_DBConfig); - $this->database = new RippingCluster_Database($this->config); - $this->config->setDatabase($this->database); - - $this->log = new RippingCluster_Log($this->database, $this->config, $log_table); - $this->request = new RippingCluster_RequestParser($request_string); - $this->cache = new RippingCluster_Cache($this->config); - - $this->smarty = new Smarty(); - $this->smarty->template_dir = './templates'; - $this->smarty->compile_dir = './tmp/templates'; - $this->smarty->cache_dir = './tmp/cache'; - $this->smarty->config_fir = './config'; - - $this->smarty->register_modifier('formatDuration', array('RippingCluster_Main', 'formatDuration')); - - $this->smarty->assign('version', '0.1'); - - $this->base_uri = dirname($_SERVER['SCRIPT_NAME']) . '/'; - $this->smarty->assign('base_uri', $this->base_uri); - - } - - /** - * - * @return RippingCluster_Main - */ - public static function instance() { - if (!self::$instance) { - self::$instance = new RippingCluster_Main(); - } - - return self::$instance; - } - - public function smarty() { - return $this->smarty; - } - - /** - * - * @return RippingCluster_Config - */ - public function config() { - return $this->config; - } - - /** - * - * @return RippingCluster_Database - */ - public function database() { - return $this->database; - } - - /** - * - * @return RippingCluster_Log - */ - public function log() { - return $this->log; - } - - /** - * - * @return RippingCluster_RequestParser - */ - public function request() { - return $this->request; - } - - /** - * - * @return RippingCluster_Cache - */ - public function cache() { - return $this->cache; - } - - public function baseUri() { - return $this->base_uri; - } - - public function absoluteUrl($relative_url) { - $secure = isset($_SERVER['secure']); - $port = $_SERVER['SERVER_PORT']; - return 'http' . ($secure ? 's' : '') . '://' - . $_SERVER['HTTP_HOST'] . (($port == 80 || ($secure && $port == 443)) ? '' : ':' . $port) - . '/' . $this->base_uri . $relative_url; - } - - public static function initialise() { - spl_autoload_register(array('RippingCluster_Main','autoload')); - } - - public static function autoload($classname) { - // Ensure the classname contains only valid class name characters - if (!preg_match('/^[A-Z][a-zA-Z0-9_]*$/', $classname)) { - throw new Exception('Illegal characters in classname'); // TODO Subclass this exception - } - - // Ensure the class to load begins with our prefix - if (!preg_match('/^RippingCluster_/', $classname)) { - return; - } - - // Special case: All exceptions are stored in the same file - if (preg_match('/^RippingCluster_Exception/', $classname)) { - require_once(RippingCluster_Lib . 'RippingCluster/Exceptions.class.php'); - return; - } - - // Replace any underscores with directory separators - $filename = RippingCluster_Lib . preg_replace('/_/', '/', $classname); - - // Tack on the class file suffix - $filename .= '.class.php'; - - // If this file exists, load it - if (file_exists($filename)) { - require_once $filename; - } - } - - public static function mkdir_recursive($directory, $permissions=0777) { - $parts = explode('/', $directory); - $path = ''; - for ($i=1,$l=count($parts); $i<=$l; $i++) { - $iPath = $parts; - $path = join('/', array_slice($iPath, 0, $i)); - if (empty($path)) continue; - if (!file_exists($path)) { - if (!mkdir($path)) return false; - if (!chmod($path, $permissions)) return false; - } - } - return true; - } - - public static function rmdir_recursive($dir) { - if (is_dir($dir)) { - $objects = scandir($dir); - foreach ($objects as $object) { - if ($object != "." && $object != "..") { - if (filetype($dir."/".$object) == "dir") self::rmdir_recursive($dir."/".$object); else unlink($dir."/".$object); - } - } - reset($objects); - rmdir($dir); - } - - return true; - } - - public static function issetelse($var, $default = null) { - if (isset($var)) { - return $var; - } - - if (is_string($default) && preg_match('/^RippingCluster_Exception/', $default) && class_exists($default) && is_subclass_of($default, RippingCluster_Exception)) { - throw new $default(); - } - - return $default; - } - - public static function formatDuration($time) { - if (is_null($time)) { - return 'unknown'; - } - - $labels = array('seconds', 'minutes', 'hours', 'days', 'weeks', 'months', 'years'); - $limits = array(1, 60, 3600, 86400, 604800, 2592000, 31556926, PHP_INT_MAX); - - $working_time = $time; - - $result = ""; - $ptr = count($labels) - 1; - - while ($ptr >= 0 && $working_time < $limits[$ptr]) { - --$ptr; - } - - while ($ptr >= 0) { - $unit_time = floor($working_time / $limits[$ptr]); - $working_time -= $unit_time * $limits[$ptr]; - $result = $result . ' ' . $unit_time . ' ' . $labels[$ptr]; - --$ptr; - } - - return $result; - } - -} - -RippingCluster_Main::initialise(); - -?> diff --git a/lib/RippingCluster/Page.class.php b/lib/RippingCluster/Page.class.php deleted file mode 100644 index 1e26dad..0000000 --- a/lib/RippingCluster/Page.class.php +++ /dev/null @@ -1,74 +0,0 @@ -smarty = $smarty; - $this->request = $request; - $this->page = $request->page(); - } - - public function page() { - return $this->page; - } - - public function template_filename() { - return $this->page . '.tpl'; - } - - public function evaluate($template_variables = array()) { - $code_filename = $this->page . '.php'; - $template_filename = $this->template_filename(); - - try { - $this->render($template_filename, $code_filename, $template_variables); - } catch (RippingCluster_Exception_AbortEntirePage $e) { - return false; - } catch (RippingCluster_Exception_FileNotFound $e) { - $this->render('errors/404.tpl', 'errors/404.php'); - } catch (RippingCluster_Exception $e) { - $this->render('errors/unhandled-exception.tpl', 'errors/unhandled-exception.php', array( - 'exception' => $e, - )); - } - - return true; - } - - protected function render($template_filename, $code_filename = null, $template_variables = array()) { - if ( ! $this->smarty->template_exists($template_filename)) { - throw new RippingCluster_Exception_FileNotFound($template_filename); - } - - // Copy all the template variables into the namespace for this function, - // so that they are readily available to the template - foreach ($template_variables as $__k => $__v) { - $$__k = $__v; - } - - // Include the template code file, which will do all the work for this page - $real_code_filename = 'pages/' . $code_filename; - if ($code_filename && file_exists($real_code_filename)) { - include $real_code_filename; - } - - // Now execute the template itself, which will render the results of the code file - $this->smarty->assign('page_content', $this->smarty->fetch($template_filename)); - } - - public static function redirect($relative_url) { - $absolute_url = RippingCluster_Main::instance()->absoluteUrl($relative_url); - - header("Location: $absolute_url"); - - throw new RippingCluster_Exception_AbortEntirePage(); - } - -}; - -?> diff --git a/lib/RippingCluster/PluginBase.class.php b/lib/RippingCluster/PluginBase.class.php deleted file mode 100644 index 7c4b264..0000000 --- a/lib/RippingCluster/PluginBase.class.php +++ /dev/null @@ -1,30 +0,0 @@ - \ No newline at end of file diff --git a/lib/RippingCluster/PluginFactory.class.php b/lib/RippingCluster/PluginFactory.class.php deleted file mode 100644 index 3827162..0000000 --- a/lib/RippingCluster/PluginFactory.class.php +++ /dev/null @@ -1,67 +0,0 @@ -getFilename()); - $plugins[] = $plugin; - } - - return $plugins; - } - - protected static function loadPlugins($plugins, $prefix, $interface) { - self::$validPlugins[get_called_class()] = array(); - - foreach ($plugins as $plugin) { - $fullClassname = $prefix . $plugin; - if ( ! class_exists($fullClassname, true)) { - continue; - } - - if ( ! in_array($interface, class_implements($fullClassname))) { - continue; - } - - // Initialise the plugin - call_user_func(array($fullClassname, 'init')); - - self::$validPlugins[get_called_class()][$plugin] = $fullClassname; - } - } - - public static function classname($plugin) { - static::ensureScanned(); - - if ( ! self::isValidPlugin($plugin)) { - throw new RippingCluster_Exception_InvalidPluginName($plugin); - } - - return self::$validPlugins[get_called_class()][$plugin]; - } - -} - -?> \ No newline at end of file diff --git a/lib/RippingCluster/RequestParser.class.php b/lib/RippingCluster/RequestParser.class.php deleted file mode 100644 index 4d1915e..0000000 --- a/lib/RippingCluster/RequestParser.class.php +++ /dev/null @@ -1,97 +0,0 @@ -request_string = $request_string; - - $this->parse(); - } - - public function parse() { - if (!$this->request_string) { - $this->page = array('home'); - return; - } - - $components = explode('/', $this->request_string); - if (!$components) { - return; - } - - // Read through the components list looking for elements matching known directories and files - // to determine which page this request is for - $base_dir = 'templates'; - while (true) { - if ($components && ! $components[0]) { - // Skip over any empty components before we find a page - array_shift($components); - } - - if ($components && is_dir($base_dir . '/' . $components[0])) { - $base_dir .= '/' . $components[0]; - array_push($this->page, array_shift($components)); - } elseif ($components && is_file($base_dir . '/' . $components[0] . '.tpl')) { - // We have found a valid page, so break the loop here, - // leaving the remaining components as key/value pairs - array_push($this->page, array_shift($components)); - break; - } else { - // See if we've already seen a component and assumed it referred to a dir when a file of the same name exists - if ($this->page && is_file($base_dir . '.tpl')) { - break; - } elseif ( ! $components && is_file($base_dir . '/index.tpl')) { - // The last component in the path was a valid directory, and a directory index exists - array_push($this->page, 'index'); - break; - } else { - // No valid page was found, so display an error page - $this->page = array('404'); - return; - } - } - } - - // The subsequent tokens are parameters for this page in key value pairs - while ($components) { - // If the url ended with a trailing slash, the last element will be null - $last_element = $components[count($components) - 1]; - if ($last_element == "") { - array_pop($components); - } - - $this->vars[array_shift($components)] = $components ? array_shift($components) : true; - } - } - - public function page() { - return join('/', $this->page); - } - - public function exists($key) { - return isset($this->vars[$key]); - } - - public function get($key, $default = null) { - if (isset($this->vars[$key])) { - return $this->vars[$key]; - } - - if (is_string($default) && preg_match('/^RippingCluster_Exception/', $default) && class_exists($default) && is_subclass_of($default, RippingCluster_Exception)) { - throw new $default(); - } - - return $default; - } - - public function request_string() { - return $this->request_string; - } - -}; - -?> diff --git a/lib/RippingCluster/Worker.class.php b/lib/RippingCluster/Worker.class.php deleted file mode 100644 index f83a8f5..0000000 --- a/lib/RippingCluster/Worker.class.php +++ /dev/null @@ -1,45 +0,0 @@ -init(); - - } - - private function init() { - if ($this->gearman) { - return; - } - - $config = RippingCluster_Main::instance()->config(); - - $this->gearman = new GearmanWorker(); - $this->gearman->addServers($config->get('rips.job_servers')); - - // Load all the plugin classes - RippingCluster_Worker_PluginFactory::scan(); - foreach (RippingCluster_Worker_PluginFactory::getValidPlugins() as $plugin) { - $workerFunctions = RippingCluster_Worker_PluginFactory::getPluginWorkerFunctions($plugin); - - foreach ($workerFunctions as $function => $callback) { - $this->gearman->addFunction($function, $callback); - } - } - } - - public function start() { - while($this->gearman->work()) { - if ($this->gearman->returnCode() != GEARMAN_SUCCESS) { - break; - } - } - - return true; - } - -} - -?> \ No newline at end of file diff --git a/lib/RippingCluster/Worker/IPlugin.class.php b/lib/RippingCluster/Worker/IPlugin.class.php deleted file mode 100644 index d3f0be2..0000000 --- a/lib/RippingCluster/Worker/IPlugin.class.php +++ /dev/null @@ -1,21 +0,0 @@ - callback) - */ - public static function workerFunctions(); - - /** - * Creates an instance of the Worker plugin, and uses it to execute a single job - * - * @param GearmanJob $job Gearman Job object, describing the work to be done - */ - public static function rip(GearmanJob $job); - -} - -?> \ No newline at end of file diff --git a/lib/RippingCluster/WorkerLogEntry.class.php b/lib/RippingCluster/WorkerLogEntry.class.php deleted file mode 100644 index ec8c11a..0000000 --- a/lib/RippingCluster/WorkerLogEntry.class.php +++ /dev/null @@ -1,13 +0,0 @@ - diff --git a/private/.gitignore b/private/.gitignore new file mode 100644 index 0000000..3630e72 --- /dev/null +++ b/private/.gitignore @@ -0,0 +1,2 @@ +config.php +dbconfig.conf diff --git a/config.php.dist b/private/config.php.dist similarity index 100% rename from config.php.dist rename to private/config.php.dist diff --git a/dbconfig.conf.dist b/private/dbconfig.conf.dist similarity index 100% rename from dbconfig.conf.dist rename to private/dbconfig.conf.dist diff --git a/lib/RippingCluster/Worker/Plugin/HandBrake.class.php b/source/lib/Net/Gearman/Job/HandBrake.class.php similarity index 53% rename from lib/RippingCluster/Worker/Plugin/HandBrake.class.php rename to source/lib/Net/Gearman/Job/HandBrake.class.php index bea4c13..e075dfe 100644 --- a/lib/RippingCluster/Worker/Plugin/HandBrake.class.php +++ b/source/lib/Net/Gearman/Job/HandBrake.class.php @@ -1,75 +1,51 @@ output = ''; - - $this->gearman_job = $gearman_job; - - $this->rip_options = unserialize($this->gearman_job->workload()); - - if ( ! $this->rip_options['id']) { - throw new RippingCluster_Exception_LogicException("Job ID must not be zero/null"); - } - $this->job = RippingCluster_Job::fromId($this->rip_options['id']); } - /** - * Returns the list of functions (and names) implemented by this plugin for registration with Gearman - * - * @return array(string => callback) - */ - public static function workerFunctions() { - return array( - 'handbrake_rip' => array(__CLASS__, 'rip'), - ); + public static function init() { + } - /** - * Creates an instance of the Worker plugin, and uses it to execute a single job - * - * @param GearmanJob $job Gearman Job object, describing the work to be done - */ - public static function rip(GearmanJob $job) { - $rip = new self($job); - $rip->execute(); - } + public static function name() { - private function execute() { + } + + public function run($args) {; $main = RippingCluster_Main::instance(); $config = $main->config(); $log = $main->log(); + $this->job = RippingCluster_Job::fromId($args['rip_options']['id']); + $handbrake_cmd_raw = array( '-n', $config->get('rips.nice'), $config->get('rips.handbrake_binary'), - $this->evaluateOption('input_filename', '-i'), - $this->evaluateOption('output_filename', '-o'), - $this->evaluateOption('title'), - $this->evaluateOption('format', '-f'), - $this->evaluateOption('video_codec', '-e'), - $this->evaluateOption('quantizer', '-q'), - $this->evaluateOption('video_width', '-w'), - $this->evaluateOption('video_height', '-l'), - $this->evaluateOption('deinterlace'), - $this->evaluateOption('audio_tracks', '-a'), - $this->evaluateOption('audio_codec', '-E'), - $this->evaluateOption('audio_names', '-A'), - $this->evaluateOption('subtitle_tracks', '-s'), + self::evaluateOption($args['rip_options'], 'input_filename', '-i'), + self::evaluateOption($args['rip_options'], 'output_filename', '-o'), + self::evaluateOption($args['rip_options'], 'title'), + self::evaluateOption($args['rip_options'], 'format', '-f'), + self::evaluateOption($args['rip_options'], 'video_codec', '-e'), + self::evaluateOption($args['rip_options'], 'quantizer', '-q'), + self::evaluateOption($args['rip_options'], 'video_width', '-w'), + self::evaluateOption($args['rip_options'], 'video_height', '-l'), + self::evaluateOption($args['rip_options'], 'deinterlace'), + self::evaluateOption($args['rip_options'], 'audio_tracks', '-a'), + self::evaluateOption($args['rip_options'], 'audio_codec', '-E'), + self::evaluateOption($args['rip_options'], 'audio_names', '-A'), + self::evaluateOption($args['rip_options'], 'subtitle_tracks', '-s'), ); $handbrake_cmd = array($config->get('rips.nice_binary')); @@ -85,24 +61,25 @@ class RippingCluster_Worker_Plugin_HandBrake extends RippingCluster_PluginBase i list($return_val, $stdout, $stderr) = RippingCluster_ForegroundTask::execute($handbrake_cmd, null, null, null, array($this, 'callbackOutput'), array($this, 'callbackOutput'), $this); if ($return_val) { - $this->gearman_job->sendFail($return_val); + $this->fail($return_val); } else { $this->job->updateStatus(RippingCluster_JobStatus::COMPLETE); + $this->complete(); } } - private function evaluateOption($name, $option = null) { + private static function evaluateOption($options, $name, $option = null) { switch($name) { case 'title': { - if (!$this->rip_options[$name] || (int)$this->rip_options[$name] < 0) { + if (!$options[$name] || (int)$options[$name] < 0) { return array('-L'); } else { - return array('-t', $this->rip_options[$name]); + return array('-t', $options[$name]); } } break; case 'deinterlace': { - switch ($this->rip_options[$name]) { + switch ($options[$name]) { case self::DEINTERLACE_ALWAYS: return array('-d'); case self::DEINTERLACE_SELECTIVELY: @@ -113,7 +90,7 @@ class RippingCluster_Worker_Plugin_HandBrake extends RippingCluster_PluginBase i } default: - return array(isset($option) ? $option : $name, $this->rip_options[$name]); + return array(isset($option) ? $option : $name, $options[$name]); } } @@ -128,6 +105,7 @@ class RippingCluster_Worker_Plugin_HandBrake extends RippingCluster_PluginBase i if (preg_match('/Encoding: task \d+ of \d+, (\d+\.\d+) %/', $line, $matches)) { $status = $rip->job->currentStatus(); $status->updateRipProgress($matches[1]); + $this->status($matches[1], 100); } else { $log = RippingCluster_Main::instance()->log(); $log->debug($line, $rip->job->id()); diff --git a/source/lib/RippingCluster/ClientLogEntry.class.php b/source/lib/RippingCluster/ClientLogEntry.class.php new file mode 100644 index 0000000..3bcd016 --- /dev/null +++ b/source/lib/RippingCluster/ClientLogEntry.class.php @@ -0,0 +1,38 @@ +jobId = $jobId; + } + + public static function fromDatabaseRow($row) { + return new self( + $row['id'], + $row['level'], + $row['ctime'], + $row['pid'], + $row['hostname'], + $row['progname'], + $row['line'], + $row['message'], + $row['job_id'] + ); + } + + public static function initialise() { + parent::$table_name = 'client_log'; + } + + public function jobId() { + return $this->jobId; + } +}; + +RippingCluster_ClientLogEntry::initialise(); + +?> diff --git a/lib/RippingCluster/Exceptions.class.php b/source/lib/RippingCluster/Exceptions.class.php similarity index 100% rename from lib/RippingCluster/Exceptions.class.php rename to source/lib/RippingCluster/Exceptions.class.php diff --git a/lib/RippingCluster/Job.class.php b/source/lib/RippingCluster/Job.class.php similarity index 95% rename from lib/RippingCluster/Job.class.php rename to source/lib/RippingCluster/Job.class.php index 1544584..c6a0ca8 100644 --- a/lib/RippingCluster/Job.class.php +++ b/source/lib/RippingCluster/Job.class.php @@ -219,11 +219,9 @@ class RippingCluster_Job { $this->id = null; } - public function queue($gearman) { + public function queue() { $main = RippingCluster_Main::instance(); $config = $main->config(); - $log = $main->log(); - $log->info('Starting job', $this->id); // Construct the rip options $rip_options = array( @@ -244,16 +242,7 @@ class RippingCluster_Job { 'subtitle_tracks' => $this->subtitle_tracks, ); - // Enqueue this rip - if ( ! $this->id) { - throw new RippingCluster_Exception_LogicException("Rip cannot be queued without being saved!"); - } - $task = $gearman->addTask('handbrake_rip', serialize($rip_options), $config->get('rips.context'), $this->id); - if ($task) { - $this->updateStatus(RippingCluster_JobStatus::QUEUED); - } else { - $this->updateStatus(RippingCluster_JobStatus::FAILED); - } + return array('HandBrake', array('rip_options' => $rip_options)); } protected function loadStatuses() { diff --git a/lib/RippingCluster/JobStatus.class.php b/source/lib/RippingCluster/JobStatus.class.php similarity index 100% rename from lib/RippingCluster/JobStatus.class.php rename to source/lib/RippingCluster/JobStatus.class.php diff --git a/source/lib/RippingCluster/Main.class.php b/source/lib/RippingCluster/Main.class.php new file mode 100644 index 0000000..09a6a22 --- /dev/null +++ b/source/lib/RippingCluster/Main.class.php @@ -0,0 +1,50 @@ +request = new RippingCluster_RequestParser($request_string); + + if (HBC_File == 'index') { + $this->smarty = new Smarty(); + $this->smarty->template_dir = './source/templates'; + $this->smarty->compile_dir = './tmp/templates'; + $this->smarty->cache_dir = './tmp/cache'; + $this->smarty->config_dir = './config'; + + $this->smarty->registerPlugin('modifier', 'formatDuration', array('RippingCluster_Main', 'formatDuration')); + + $this->smarty->assign('version', '0.1'); + $this->smarty->assign('messages', array()); + + $this->smarty->assign('base_uri', $this->base_uri); + } + } + + public function smarty() { + return $this->smarty; + } + + /** + * + * @return RippingCluster_RequestParser + */ + public function request() { + return $this->request; + } + + +} + +?> diff --git a/lib/RippingCluster/Rips/SourceAudioTrack.class.php b/source/lib/RippingCluster/Rips/SourceAudioTrack.class.php similarity index 98% rename from lib/RippingCluster/Rips/SourceAudioTrack.class.php rename to source/lib/RippingCluster/Rips/SourceAudioTrack.class.php index 6b7e81e..3db2d1f 100644 --- a/lib/RippingCluster/Rips/SourceAudioTrack.class.php +++ b/source/lib/RippingCluster/Rips/SourceAudioTrack.class.php @@ -25,7 +25,7 @@ class RippingCluster_Rips_SourceAudioTrack { } public function name() { - return $name; + return $this->name; } public function setName($name) { diff --git a/lib/RippingCluster/Rips/SourceSubtitleTrack.class.php b/source/lib/RippingCluster/Rips/SourceSubtitleTrack.class.php similarity index 100% rename from lib/RippingCluster/Rips/SourceSubtitleTrack.class.php rename to source/lib/RippingCluster/Rips/SourceSubtitleTrack.class.php diff --git a/lib/RippingCluster/Rips/SourceTitle.class.php b/source/lib/RippingCluster/Rips/SourceTitle.class.php similarity index 100% rename from lib/RippingCluster/Rips/SourceTitle.class.php rename to source/lib/RippingCluster/Rips/SourceTitle.class.php diff --git a/lib/RippingCluster/Source.class.php b/source/lib/RippingCluster/Source.class.php similarity index 100% rename from lib/RippingCluster/Source.class.php rename to source/lib/RippingCluster/Source.class.php diff --git a/lib/RippingCluster/Source/IPlugin.class.php b/source/lib/RippingCluster/Source/IPlugin.class.php similarity index 100% rename from lib/RippingCluster/Source/IPlugin.class.php rename to source/lib/RippingCluster/Source/IPlugin.class.php diff --git a/lib/RippingCluster/Source/Plugin/Bluray.class.php b/source/lib/RippingCluster/Source/Plugin/Bluray.class.php similarity index 100% rename from lib/RippingCluster/Source/Plugin/Bluray.class.php rename to source/lib/RippingCluster/Source/Plugin/Bluray.class.php diff --git a/lib/RippingCluster/Source/Plugin/HandBrake.class.php b/source/lib/RippingCluster/Source/Plugin/HandBrake.class.php similarity index 100% rename from lib/RippingCluster/Source/Plugin/HandBrake.class.php rename to source/lib/RippingCluster/Source/Plugin/HandBrake.class.php diff --git a/lib/RippingCluster/Source/Plugin/MkvInfo.class.php b/source/lib/RippingCluster/Source/Plugin/MkvInfo.class.php similarity index 100% rename from lib/RippingCluster/Source/Plugin/MkvInfo.class.php rename to source/lib/RippingCluster/Source/Plugin/MkvInfo.class.php diff --git a/lib/RippingCluster/Source/PluginFactory.class.php b/source/lib/RippingCluster/Source/PluginFactory.class.php similarity index 82% rename from lib/RippingCluster/Source/PluginFactory.class.php rename to source/lib/RippingCluster/Source/PluginFactory.class.php index 5b3e44b..f5b46b4 100644 --- a/lib/RippingCluster/Source/PluginFactory.class.php +++ b/source/lib/RippingCluster/Source/PluginFactory.class.php @@ -2,20 +2,17 @@ class RippingCluster_Source_PluginFactory extends RippingCluster_PluginFactory { - const PLUGIN_DIR = 'RippingCluster/Source/Plugin/'; - const PLUGIN_PREFIX = 'RippingCluster_Source_Plugin_'; - const PLUGIN_INTERFACE = 'RippingCluster_Source_IPlugin'; + protected static $plugin_prefix = 'RippingCluster_Source_Plugin_'; + protected static $plugin_interface = 'RippingCluster_Source_IPlugin'; + protected static $plugin_dir = array( + RippingCluster_Lib => 'RippingCluster/Source/Plugin/', + ); + public static function init() { } - public static function scan() { - $candidatePlugins = parent::findPlugins(self::PLUGIN_DIR); - - self::loadPlugins($candidatePlugins, self::PLUGIN_PREFIX, self::PLUGIN_INTERFACE); - } - public static function enumerate($plugin) { self::ensureScanned(); @@ -57,7 +54,7 @@ class RippingCluster_Source_PluginFactory extends RippingCluster_PluginFactory { return call_user_func(array(self::classname($plugin), 'loadEncoded'), $encoded_filename, $scan, $use_cache); } - public static function isValidSource($plugin, $source_filename) { + /*public static function isValidSource($plugin, $source_filename) { self::ensureScanned(); if ( ! self::isValidPlugin($plugin)) { @@ -65,7 +62,7 @@ class RippingCluster_Source_PluginFactory extends RippingCluster_PluginFactory { } return call_user_func(array(self::classname($plugin), 'isValidSource'), source_filename); - } + }*/ /** * Permanently deletes the given source from disk diff --git a/lib/RippingCluster/Utility/BlurayDirectoryIterator.class.php b/source/lib/RippingCluster/Utility/BlurayDirectoryIterator.class.php similarity index 100% rename from lib/RippingCluster/Utility/BlurayDirectoryIterator.class.php rename to source/lib/RippingCluster/Utility/BlurayDirectoryIterator.class.php diff --git a/lib/RippingCluster/Utility/ClassFilesIterator.class.php b/source/lib/RippingCluster/Utility/ClassFilesIterator.class.php similarity index 100% rename from lib/RippingCluster/Utility/ClassFilesIterator.class.php rename to source/lib/RippingCluster/Utility/ClassFilesIterator.class.php diff --git a/lib/RippingCluster/Utility/DvdDirectoryIterator.class.php b/source/lib/RippingCluster/Utility/DvdDirectoryIterator.class.php similarity index 100% rename from lib/RippingCluster/Utility/DvdDirectoryIterator.class.php rename to source/lib/RippingCluster/Utility/DvdDirectoryIterator.class.php diff --git a/lib/RippingCluster/Utility/MkvFileIterator.class.php b/source/lib/RippingCluster/Utility/MkvFileIterator.class.php similarity index 100% rename from lib/RippingCluster/Utility/MkvFileIterator.class.php rename to source/lib/RippingCluster/Utility/MkvFileIterator.class.php diff --git a/lib/RippingCluster/Utility/VisibleFilesIterator.class.php b/source/lib/RippingCluster/Utility/VisibleFilesIterator.class.php similarity index 100% rename from lib/RippingCluster/Utility/VisibleFilesIterator.class.php rename to source/lib/RippingCluster/Utility/VisibleFilesIterator.class.php diff --git a/lib/RippingCluster/Utility/VisibleFilesRecursiveIterator.class.php b/source/lib/RippingCluster/Utility/VisibleFilesRecursiveIterator.class.php similarity index 100% rename from lib/RippingCluster/Utility/VisibleFilesRecursiveIterator.class.php rename to source/lib/RippingCluster/Utility/VisibleFilesRecursiveIterator.class.php diff --git a/source/lib/RippingCluster/Worker.class.php b/source/lib/RippingCluster/Worker.class.php new file mode 100644 index 0000000..4bfabcf --- /dev/null +++ b/source/lib/RippingCluster/Worker.class.php @@ -0,0 +1,47 @@ +init(); + + } + + private function init() { + if ($this->gearman) { + return; + } + + $config = RippingCluster_Main::instance()->config(); + + $this->gearman = new Net_Gearman_Worker('river.sihnon.net:4730');//$config->get('rips.job_servers')); + + // Load all the plugin classes + RippingCluster_Worker_PluginFactory::scan(); + $plugins = RippingCluster_Worker_PluginFactory::getValidPlugins(); + foreach ($plugins as $plugin) { + $this->gearman->addAbility($plugin); + + //$workerFunctions = RippingCluster_Worker_PluginFactory::getPluginWorkerFunctions($plugin); + //foreach ($workerFunctions as $function => $callback) { + // echo "Added ability $function\n"; + // $this->gearman->addAbility($function); + //} + } + } + + public function start() { + try { + $this->gearman->beginWork(); + } catch (Net_Gearman_Exception $e) { + // Do stuff + } + + return true; + } + +} + +?> \ No newline at end of file diff --git a/source/lib/RippingCluster/Worker/IPlugin.class.php b/source/lib/RippingCluster/Worker/IPlugin.class.php new file mode 100644 index 0000000..d054e4a --- /dev/null +++ b/source/lib/RippingCluster/Worker/IPlugin.class.php @@ -0,0 +1,16 @@ + callback) + */ + //public static function workerFunctions(); + + //public static function run($args); + +} + +?> \ No newline at end of file diff --git a/lib/RippingCluster/Worker/Plugin/Bluray.class.php b/source/lib/RippingCluster/Worker/Plugin/Bluray.class.php similarity index 86% rename from lib/RippingCluster/Worker/Plugin/Bluray.class.php rename to source/lib/RippingCluster/Worker/Plugin/Bluray.class.php index a25b40d..1b6ea12 100644 --- a/lib/RippingCluster/Worker/Plugin/Bluray.class.php +++ b/source/lib/RippingCluster/Worker/Plugin/Bluray.class.php @@ -51,6 +51,11 @@ class RippingCluster_Worker_Bluray extends RippingCluster_PluginBase implements $this->job = RippingCluster_Job::fromId($this->rip_options['id']); } + public static function init() { + // Nothing to do + } + + /** * Returns the list of functions (and names) implemented by this plugin for registration with Gearman * @@ -62,14 +67,9 @@ class RippingCluster_Worker_Bluray extends RippingCluster_PluginBase implements ); } - /** - * Creates an instance of the Worker plugin, and uses it to execute a single job - * - * @param GearmanJob $job Gearman Job object, describing the work to be done - */ - public static function rip(GearmanJob $job) { - $rip = new self($job); - $rip->execute(); + public static function run($args) { + //$rip = new self($job); + //$rip->execute(); } /** diff --git a/lib/RippingCluster/Worker/Plugin/FfmpegTranscode.class.php b/source/lib/RippingCluster/Worker/Plugin/FfmpegTranscode.class.php similarity index 86% rename from lib/RippingCluster/Worker/Plugin/FfmpegTranscode.class.php rename to source/lib/RippingCluster/Worker/Plugin/FfmpegTranscode.class.php index 8d63063..4170a25 100644 --- a/lib/RippingCluster/Worker/Plugin/FfmpegTranscode.class.php +++ b/source/lib/RippingCluster/Worker/Plugin/FfmpegTranscode.class.php @@ -62,14 +62,9 @@ class RippingCluster_Worker_FfmpegTranscode extends RippingCluster_PluginBase im ); } - /** - * Creates an instance of the Worker plugin, and uses it to execute a single job - * - * @param GearmanJob $job Gearman Job object, describing the work to be done - */ - public static function rip(GearmanJob $job) { - $rip = new self($job); - $rip->execute(); + public static function run($args) { + //$rip = new self($job); + //$rip->execute(); } /** diff --git a/lib/RippingCluster/Worker/PluginFactory.class.php b/source/lib/RippingCluster/Worker/PluginFactory.class.php similarity index 84% rename from lib/RippingCluster/Worker/PluginFactory.class.php rename to source/lib/RippingCluster/Worker/PluginFactory.class.php index 21afcaa..541ae91 100644 --- a/lib/RippingCluster/Worker/PluginFactory.class.php +++ b/source/lib/RippingCluster/Worker/PluginFactory.class.php @@ -2,8 +2,8 @@ class RippingCluster_Worker_PluginFactory extends RippingCluster_PluginFactory { - const PLUGIN_DIR = 'RippingCluster/Worker/Plugin/'; - const PLUGIN_PREFIX = 'RippingCluster_Worker_Plugin_'; + const PLUGIN_DIR = 'Net/Gearman/Job/'; + const PLUGIN_PREFIX = 'Net_Gearman_Job_'; const PLUGIN_INTERFACE = 'RippingCluster_Worker_IPlugin'; public static function init() { diff --git a/source/lib/RippingCluster/WorkerLogEntry.class.php b/source/lib/RippingCluster/WorkerLogEntry.class.php new file mode 100644 index 0000000..9439ba0 --- /dev/null +++ b/source/lib/RippingCluster/WorkerLogEntry.class.php @@ -0,0 +1,39 @@ +jobId = $jobId; + } + + public static function fromDatabaseRow($row) { + return new self( + $row['id'], + $row['level'], + $row['ctime'], + $row['pid'], + $row['hostname'], + $row['progname'], + $row['line'], + $row['message'], + $row['job_id'] + ); + } + + public static function initialise() { + parent::$table_name = 'worker_log'; + } + + public function jobId() { + return $this->jobId; + } + +}; + +RippingCluster_WorkerLogEntry::initialise(); + +?> diff --git a/webui/_inc.php b/webui/_inc.php index b4840b6..03fa775 100644 --- a/webui/_inc.php +++ b/webui/_inc.php @@ -1,6 +1,10 @@ diff --git a/webui/run-jobs.php b/webui/run-jobs.php index afd64ee..75ca6eb 100644 --- a/webui/run-jobs.php +++ b/webui/run-jobs.php @@ -2,36 +2,38 @@ define('HBC_File', 'run-jobs'); -require_once '../config.php'; -require_once RippingCluster_Lib . 'RippingCluster/Main.class.php'; +require_once '../private/config.php'; +require_once(SihnonFramework_Lib . 'SihnonFramework/Main.class.php'); +require_once 'Net/Gearman/Client.php'; + +SihnonFramework_Main::registerAutoloadClasses('Sihnon', SihnonFramework_Lib, + 'RippingCluster', SihnonFramework_Main::makeAbsolutePath('../lib/')); try { $main = RippingCluster_Main::instance(); $config = $main->config(); $log = $main->log(); - $gearman = new GearmanClient(); - $gearman->addServers($config->get('rips.job_servers')); - $gearman->setCreatedCallback("gearman_created_callback"); - $gearman->setDataCallback("gearman_data_callback"); - $gearman->setCompleteCallback("gearman_complete_callback"); - $gearman->setFailCallback("gearman_fail_callback"); + $client = new Net_Gearman_Client('river.sihnon.net:4730');//$config->get('rips.job_servers')); + $set = new Net_Gearman_Set(); // Retrieve a list of Created jobs $jobs = RippingCluster_Job::allWithStatus(RippingCluster_JobStatus::CREATED); foreach ($jobs as $job) { // Enqueue the job using gearman - $job->queue($gearman); + list($method, $rip_options) = $job->queue(); + $task = new Net_Gearman_Task($method, $rip_options); + $task->attachCallback('gearman_complete', Net_Gearman_Task::TASK_COMPLETE); + $task->attachCallback('gearman_fail', Net_Gearman_Task::TASK_FAIL); + $set->addTask($task); + + $job->updateStatus(RippingCluster_JobStatus::QUEUED); } // Start the job queue - $result = $gearman->runTasks(); - if (!$result) { - $log->error($gearman->error()); - die($gearman->error()); - } - + $result = $client->runSet($set); + $log->info("Job queue completed"); } catch (RippingCluster_Exception $e) { @@ -39,35 +41,23 @@ try { } -function gearman_created_callback($gearman_task) { - $main = RippingCluster_Main::instance(); - $log = $main->log(); - - $log->info("Job successfully queued with Gearman", $gearman_task->unique()); -} - -function gearman_data_callback($gearman_task) { +function gearman_complete($method, $handle, $result) { $main = RippingCluster_Main::instance(); $log = $main->log(); - $log->debug("Received data callback from Gearman Task"); + /*$log->info("Job Complete", $job->id());*/ + $log->info("Job complete"); } -function gearman_complete_callback($gearman_task) { +function gearman_fail($task) { $main = RippingCluster_Main::instance(); $log = $main->log(); - $log->info("Job Complete", $job->id()); -} - -function gearman_fail_callback($gearman_task) { - $main = RippingCluster_Main::instance(); - $log = $main->log(); - - $job = RippingCluster_Job::fromId($gearman_task->unique()); + /*$job = RippingCluster_Job::fromId($gearman_task->unique()); $job->updateStatus(RippingCluster_JobStatus::FAILED); - $log->info("Job Failed", $job->id()); + $log->info("Job Failed", $job->id());*/ + $log->info("Job failed"); } diff --git a/webui/pages/errors/404.php b/webui/source/pages/errors/404.php similarity index 100% rename from webui/pages/errors/404.php rename to webui/source/pages/errors/404.php diff --git a/webui/pages/errors/unhandled-exception.php b/webui/source/pages/errors/unhandled-exception.php similarity index 100% rename from webui/pages/errors/unhandled-exception.php rename to webui/source/pages/errors/unhandled-exception.php diff --git a/webui/pages/home.php b/webui/source/pages/home.php similarity index 100% rename from webui/pages/home.php rename to webui/source/pages/home.php diff --git a/webui/pages/job-details.php b/webui/source/pages/job-details.php similarity index 100% rename from webui/pages/job-details.php rename to webui/source/pages/job-details.php diff --git a/webui/pages/jobs.php b/webui/source/pages/jobs.php similarity index 100% rename from webui/pages/jobs.php rename to webui/source/pages/jobs.php diff --git a/webui/pages/logs.php b/webui/source/pages/logs.php similarity index 100% rename from webui/pages/logs.php rename to webui/source/pages/logs.php diff --git a/webui/pages/rips/setup-rip.php b/webui/source/pages/rips/setup-rip.php similarity index 100% rename from webui/pages/rips/setup-rip.php rename to webui/source/pages/rips/setup-rip.php diff --git a/webui/pages/rips/source-details.php b/webui/source/pages/rips/source-details.php similarity index 100% rename from webui/pages/rips/source-details.php rename to webui/source/pages/rips/source-details.php diff --git a/webui/pages/rips/sources.php b/webui/source/pages/rips/sources.php similarity index 100% rename from webui/pages/rips/sources.php rename to webui/source/pages/rips/sources.php diff --git a/webui/pages/sources/delete.php b/webui/source/pages/sources/delete.php similarity index 100% rename from webui/pages/sources/delete.php rename to webui/source/pages/sources/delete.php diff --git a/webui/templates/admin/settings.tpl b/webui/source/templates/admin/settings.tpl similarity index 100% rename from webui/templates/admin/settings.tpl rename to webui/source/templates/admin/settings.tpl diff --git a/webui/templates/errors/404.tpl b/webui/source/templates/errors/404.tpl similarity index 100% rename from webui/templates/errors/404.tpl rename to webui/source/templates/errors/404.tpl diff --git a/webui/templates/errors/unhandled-exception.tpl b/webui/source/templates/errors/unhandled-exception.tpl similarity index 100% rename from webui/templates/errors/unhandled-exception.tpl rename to webui/source/templates/errors/unhandled-exception.tpl diff --git a/webui/templates/home.tpl b/webui/source/templates/home.tpl similarity index 100% rename from webui/templates/home.tpl rename to webui/source/templates/home.tpl diff --git a/webui/templates/index.tpl b/webui/source/templates/index.tpl similarity index 93% rename from webui/templates/index.tpl rename to webui/source/templates/index.tpl index f7e2bb7..0a54450 100644 --- a/webui/templates/index.tpl +++ b/webui/source/templates/index.tpl @@ -19,13 +19,13 @@