Update directory layout to fit with other projects

This commit is contained in:
2012-01-11 00:28:17 +00:00
parent 06e3d65ffa
commit 4486af7be8
86 changed files with 15 additions and 8 deletions

View File

@@ -0,0 +1,11 @@
<?php
$main = RippingCluster_Main::instance();
$config = $main->config();
$settings = $config->enumerateAll();
asort($settings);
$this->smarty->assign('settings', $settings);
$this->smarty->assign('config', $config);
?>

View File

@@ -0,0 +1,55 @@
<?php
$main = RippingCluster_Main::instance();
$req = $main->request();
$config = $main->config();
$messages = array();
$result = false;
try {
$name = $req->get('name', 'RippingCluster_Exception_InvalidParameters');
$type = $req->get('type', 'RippingCluster_Exception_InvalidParameters');
// Convert the web-friendly type field into the correct internal name
$value = null;
switch($type) {
case 'bool': {
$type = Sihnon_Config::TYPE_BOOL;
$value = false;
} break;
case 'int': {
$type = Sihnon_Config::TYPE_INT;
$value = 0;
} break;
case 'string': {
$type = Sihnon_Config::TYPE_STRING;
$value = '';
} break;
case 'string-list': {
$type = Sihnon_Config::TYPE_STRING_LIST;
$value = array();
} break;
case 'hash': {
$type = Sihnon_Config::TYPE_HASH;
$value = array();
} break;
}
// Add the new (empty) value. This is because no suitable UI has been presented yet.
// Possible future fix, to insert intermediate dialog to capture the value using the correct UI.
$result = $config->add($name, $type, $value);
$this->smarty->assign('success', $result);
$this->smarty->assign('name', $name);
$this->smarty->assign('id', str_replace('.', '-',$name));
$this->smarty->assign('type', $type);
$this->smarty->assign('value', '');
} catch(RippingCluster_Exception $e) {
$messages[] = get_class($e) . ':' . $e->getMessage();
$this->smarty->assign('messages', $messages);
$this->smarty->assign('success', false);
}
?>

View File

@@ -0,0 +1,23 @@
<?php
$main = RippingCluster_Main::instance();
$req = $main->request();
$config = $main->config();
$messages = array();
$result = false;
try {
$name = $req->get('name', 'RippingCluster_Exception_InvalidParameters');
$result = $config->remove($name);
$this->smarty->assign('success', $result);
} catch(RippingCluster_Exception $e) {
$messages[] = get_class($e) . ':' . $e->getMessage();
$this->smarty->assign('messages', $messages);
$this->smarty->assign('success', false);
}
?>

View File

@@ -0,0 +1,39 @@
<?php
$main = RippingCluster_Main::instance();
$req = $main->request();
$config = $main->config();
$messages = array();
$result = false;
$confirm = $req->exists('confirm');
$this->smarty->assign('confirm', $confirm);
if ($confirm) {
try {
$name = $req->get('name', 'RippingCluster_Exception_InvalidParameters');
$new_name = $req->get('new-name', 'RippingCluster_Exception_InvalidParameters');
$result = $config->rename($name, $new_name);
$this->smarty->assign('success', $result);
$this->smarty->assign('old_name', $name);
$this->smarty->assign('old_id', str_replace('.', '-', $name));
$this->smarty->assign('name', $new_name);
$this->smarty->assign('id', str_replace('.', '-', $new_name));
$this->smarty->assign('type', $config->type($new_name));
$this->smarty->assign('value', $config->get($new_name));
} catch(RippingCluster_Exception $e) {
$messages[] = get_class($e) . ':' . $e->getMessage();
$this->smarty->assign('messages', $messages);
$this->smarty->assign('success', false);
}
} else {
$name = $req->get('name', 'RippingCluster_Exception_InvalidParameters');
$this->smarty->assign('name', $name);
}
?>

View File

@@ -0,0 +1,35 @@
<?php
$main = RippingCluster_Main::instance();
$req = $main->request();
$config = $main->config();
// Grab the name of this source
$encoded_filename = null;
if ($req->exists('confirm')) {
$this->smarty->assign('confirmed', true);
$plugin = $req->get('plugin', 'RippingCluster_Exception_InvalidParameters');
$encoded_filename = $req->get('id', 'RippingCluster_Exception_InvalidParameters');
$source = RippingCluster_Source_PluginFactory::loadEncoded($plugin, $encoded_filename, false);
$source->delete();
// Generate a new list of sources to update the page with
$all_sources = RippingCluster_Source_PluginFactory::enumerateAll();
$this->smarty->assign('all_sources', $all_sources);
} else {
$this->smarty->assign('confirmed', false);
$plugin = $req->get('plugin', 'RippingCluster_Exception_InvalidParameters');
$encoded_filename = $req->get('id', 'RippingCluster_Exception_InvalidParameters');
$source = RippingCluster_Source_PluginFactory::loadEncoded($plugin, $encoded_filename, false);
$this->smarty->assign('source', $source);
$this->smarty->assign('source_plugin', $plugin);
$this->smarty->assign('source_id', $encoded_filename);
}
?>

View File

@@ -0,0 +1,9 @@
<?php
$main = RippingCluster_Main::instance();
$config = $main->config();
$all_sources = RippingCluster_Source_PluginFactory::enumerateAll();
$this->smarty->assign('all_sources', $all_sources);
?>

View File

@@ -0,0 +1,22 @@
<?php
$main = RippingCluster_Main::instance();
$config = $main->config();
$messages = array();
// Iterate over the settings and store each one back to the backend
foreach($_POST as $key => $value) {
// Convert - to . (to work around the PHP register global backwards compatibility that renames input variables)
$key = str_replace("-", ".", $key);
if ($config->exists($key)) {
$config->set($key, $value);
} else {
$messages[] = "Unknown config key '{$key}', value not updated.";
}
}
$this->smarty->assign('messages', $messages);
?>

View File

@@ -0,0 +1,9 @@
<?php
$main = RippingCluster_Main::instance();
$req = $main->request();
$this->smarty->assign('requested_page', htmlspecialchars($req->request_string()));
?>

View File

@@ -0,0 +1,10 @@
<?php
$main = RippingCluster_Main::instance();
$config = $main->config();
$this->smarty->assign('display_exceptions', $config->get('debug.display_exceptions'));
$this->smarty->assign('exception', $exception);
$this->smarty->assign('exception_type', get_class($exception));
?>

View File

@@ -0,0 +1,13 @@
<?php
$running_jobs = RippingCluster_Job::allWithStatus(RippingCluster_JobStatus::RUNNING, 10);
$queued_jobs = RippingCluster_Job::allWithStatus(RippingCluster_JobStatus::QUEUED, 10);
$completed_jobs = RippingCluster_Job::allWithStatus(RippingCluster_JobStatus::COMPLETE, 10);
$failed_jobs = RippingCluster_Job::allWithStatus(RippingCluster_JobStatus::FAILED, 10);
$this->smarty->assign('running_jobs', $running_jobs);
$this->smarty->assign('queued_jobs', $queued_jobs);
$this->smarty->assign('completed_jobs', $completed_jobs);
$this->smarty->assign('failed_jobs', $failed_jobs);
?>

View File

@@ -0,0 +1,96 @@
<?php
$main = RippingCluster_Main::instance();
$req = $main->request();
$config = $main->config();
if ($req->exists('submit')) {
$action = RippingCluster_Main::issetelse($_POST['action'], 'RippingCluster_Exception_InvalidParameters');
# If a bulk action was selected, the action will be a single term, otherwise it will also contain
# the id of the single item to act upon. Work out which was used now.
$matches = $job_ids = array();
if (preg_match('/^(.*)\[(\d+)\]$/', $action, $matches)) {
$action = $matches[1];
$job_ids = array($matches[2]);
}
else {
$job_ids = $_POST['include'];
}
$jobs = array();
foreach ($job_ids as $job_id) {
$job = RippingCluster_Job::fromId($job_id);
if (!$job) {
throw new RippingCluster_Exception_InvalidParameters('job_id');
}
$jobs[] = $job;
}
switch ($action) {
case 'mark-failed': {
foreach ($jobs as $job) {
$job->updateStatus(RippingCluster_JobStatus::FAILED);
}
} break;
case 'retry': {
# Clone each of the selected jobs
foreach ($jobs as $job) {
$new_job = clone $job;
}
# Dispatch all the jobs in one run
RippingCluster_Job::runAllJobs();
# Redirect to the job queued page to show the jobs were successfully dispatched
RippingCluster_Page::redirect('rips/setup/queued');
} break;
case 'delete': {
foreach ($jobs as $job) {
$job->delete();
}
} break;
case 'fix-broken-timestamps': {
foreach ($jobs as $job) {
$job->fixBrokenTimestamps();
}
} break;
default: {
throw new RippingCluster_Exception_InvalidParameters('action');
}
}
RippingCluster_Page::redirect('jobs');
} else {
if (isset($_POST['view'])) {
$statusName = urlencode($_POST['view']);
RippingCluster_Page::redirect("jobs/view/{$statusName}");
}
$statusName = $req->get('view', 'any');
switch ($statusName) {
case 'any': $status = null; break;
case 'queued': $status = RippingCluster_JobStatus::QUEUED; break;
case 'running': $status = RippingCluster_JobStatus::RUNNING; break;
case 'complete': $status = RippingCluster_JobStatus::COMPLETE; break;
case 'failed': $status = RippingCluster_JobStatus::FAILED; break;
default: throw new RippingCluster_Exception_InvalidParameters('view');
}
$jobs = array();
if ($status) {
$jobs = RippingCluster_Job::allWithStatus($status);
} else {
$jobs = RippingCluster_Job::all();
}
$this->smarty->assign('jobs', $jobs);
}
?>

View File

@@ -0,0 +1,45 @@
<?php
$main = RippingCluster_Main::instance();
$req = $main->request();
$log = $main->log();
$config = $main->config();
$job_id = $req->get('id');
$job = RippingCluster_Job::fromId($job_id);
$this->smarty->assign('job', $job);
// Fetch log entries for this job
$log_count = $req->get('logs', $config->get('job.logs.default_display_count'));
$default_log_order = $config->get('job.logs.default_order');
$log_order = $req->get('order', $default_log_order);
if ( ! in_array($log_order, array(SihnonFramework_Log::ORDER_ASC, SihnonFramework_Log::ORDER_DESC))) {
$log_order = $default_log_order;
}
$this->smarty->assign('log_order', $log_order);
$this->smarty->assign('log_order_reverse', ($log_order == SihnonFramework_Log::ORDER_ASC ? SihnonFramework_Log::ORDER_DESC : SihnonFramework_Log::ORDER_ASC));
$client_log_entries = array();
$worker_log_entries = array();
$log_count_display = null;
if ($log_count == 'all') {
$log_count_display = 'all';
$log_count = '18446744073709551615'; // see mysql man page for LIMIT
} else if(!is_int($log_count)) {
$log_count = $config->get('job.logs.default_display_count');
$log_count_display = $log_count;
} else {
$log_count_display = $log_count;
}
$client_log_entries = RippingCluster_LogEntry::recentEntriesByField($log, 'webui', 'job_id', $job_id, 'ctime', $log_order, $log_count);
$worker_log_entries = RippingCluster_LogEntry::recentEntriesByField($log, 'worker', 'job_id', $job_id, 'ctime', $log_order, $log_count);
$this->smarty->assign('log_count_display', $log_count_display);
$this->smarty->assign('client_log_entries', $client_log_entries);
$this->smarty->assign('worker_log_entries', $worker_log_entries);
?>

View File

@@ -0,0 +1,11 @@
<?php
$log = RippingCluster_Main::instance()->log();
$client_log_entries = RippingCluster_LogEntry::recentEntries($log, 'webui', 'ctime', SihnonFramework_Log::ORDER_DESC, 30);
$worker_log_entries = RippingCluster_LogEntry::recentEntries($log, 'worker', 'ctime', SihnonFramework_Log::ORDER_DESC, 30);
$this->smarty->assign('client_log_entries', $client_log_entries);
$this->smarty->assign('worker_log_entries', $worker_log_entries);
?>

View File

@@ -0,0 +1,49 @@
<?php
$main = RippingCluster_Main::instance();
$req = $main->request();
$config = $main->config();
// Grab the name of this source
$encoded_filename = null;
if ($req->exists('submit')) {
$encoded_filename = RippingCluster_Main::issetelse($_POST['id'], 'RippingCluster_Exception_InvalidParameters');
// Update the recently used list
$recent_output_directories = $config->get('rips.output_directories.recent');
if ( ! in_array($_POST['rip-options']['output-directory'], $recent_output_directories)) {
array_unshift($recent_output_directories, $_POST['rip-options']['output-directory']);
$config->set('rips.output_directories.recent', array_slice($recent_output_directories, 0, $config->get('rips.output_directories.recent_limit', 10)));
}
// Create the jobs from the request
$jobs = RippingCluster_Job::fromPostRequest($_POST['plugin'], $_POST['id'], $_POST['rip-options'], $_POST['rips']);
// Spawn the background client process to run all the jobs
RippingCluster_Job::runAllJobs();
RippingCluster_Page::redirect('rips/setup/queued');
} elseif ($req->exists('queued')) {
$this->smarty->assign('rips_submitted', true);
} else {
$this->smarty->assign('rips_submitted', false);
$encoded_filename = $req->get('id', 'RippingCluster_Exception_InvalidParameters');
$plugin = $req->get('plugin', 'RippingCluster_Exception_InvalidParameters');
$source = RippingCluster_Source_PluginFactory::loadEncoded($plugin, $encoded_filename);
$this->smarty->assign('source', $source);
$this->smarty->assign('titles', $source->titles());
$this->smarty->assign('longest_title', $source->longestTitle());
$this->smarty->assign('default_output_directory', $config->get('rips.default.output_directory'));
$default_output_directories = $config->get('rips.output_directories.default');
$recent_output_directories = $config->get('rips.output_directories.recent');
$this->smarty->assign('default_output_directories', $default_output_directories);
$this->smarty->assign('recent_output_directories', $recent_output_directories);
$this->smarty->assign('next_output_directory_index', count($default_output_directories) + count($recent_output_directories) + 1);
}
?>

View File

@@ -0,0 +1,28 @@
<?php
$main = RippingCluster_Main::instance();
$req = $main->request();
$config = $main->config();
// Grab the name of this source
$encoded_filename = null;
if ($req->exists('confirm')) {
$plugin = $req->get('plugin', 'RippingCluster_Exception_InvalidParameters');
$encoded_filename = $req->get('id', 'RippingCluster_Exception_InvalidParameters');
$source = RippingCluster_Source_PluginFactory::loadEncoded($plugin, $encoded_filename, false);
$source->delete();
// Redirect back to the sources page
RippingCluster_Page::redirect('rips/sources');
} else {
$plugin = $req->get('plugin', 'RippingCluster_Exception_InvalidParameters');
$encoded_filename = $req->get('id', 'RippingCluster_Exception_InvalidParameters');
$source = RippingCluster_Source_PluginFactory::loadEncoded($plugin, $encoded_filename, false);
$this->smarty->assign('source', $source);
}
?>

View File

@@ -0,0 +1,13 @@
<?php
$main = RippingCluster_Main::instance();
$req = $main->request();
$config = $main->config();
$plugin = $req->get('plugin', 'RippingCluster_Exception_InvalidParameters');
$source = RippingCluster_Source_PluginFactory::loadEncoded($plugin, $req->get('id', 'RippingCluster_Exception_InvalidParameters'));
$this->smarty->assign('source', $source);
$this->smarty->assign('titles', $source->titles());
?>

View File

@@ -0,0 +1,9 @@
<?php
$main = RippingCluster_Main::instance();
$config = $main->config();
$all_sources = RippingCluster_Source_PluginFactory::enumerateAll();
$this->smarty->assign('all_sources', $all_sources);
?>