public function Fire() { if (!$this->input->name) { TaskPump::Pump()->QueueTask(new ErrorTask('Name is required.')); return; } if (!$this->input->episode) { TaskPump::Pump()->QueueTask(new ErrorTask('Episode (SxE) is required.')); return; } if (!$this->input->feed_url) { TaskPump::Pump()->QueueTask(new ErrorTask('Feed URL is required.')); return; } $episode = Episode::SplitEpisodeNumber($this->input->episode); if (!$episode) { TaskPump::Pump()->QueueTask(new ErrorTask('Episode format is invalid (SxE).')); return; } $show = new Show(); $show->name = $this->input->name; $show->search_url = $this->input->feed_url; $show->last_season = $episode[0]; $show->last_episode = $episode[1]; try { $show->Insert(); } catch (\phalanx\data\ModelException $e) { TaskPump::Pump()->QueueTask(new ErrorTask('An error occurred while adding the show.')); return; } $str = 'Added ' . $show->name . ' at ' . $show->last_season . 'x' . $show->last_episode; TaskPump::Pump()->QueueTask(new MessageTask($str)); }
public function setUp() { $this->pump = $this->getMock('phalanx\\tasks\\TaskPump', array('_Exit')); tasks\TaskPump::T_set_pump($this->pump); $this->handler = new tasks\UnitTestOutputHandler(); $this->pump->set_output_handler($this->handler); }
public function testSetPump() { $this->assertNotNull($this->dispatcher->pump()); $this->assertSame(tasks\TaskPump::Pump(), $this->dispatcher->pump()); $pump = new tasks\TaskPump(); $this->dispatcher->set_pump($pump); $this->assertSame($pump, $this->dispatcher->pump()); }
public function setUp() { $this->handler = new tasks\ViewOutputHandler(); $this->pump = $this->getMock('phalanx\\tasks\\TaskPump', array('_Exit')); tasks\TaskPump::T_set_pump($this->pump); $this->tpl_path = TestView::template_path(); $this->cache_path = TestView::cache_path(); }
public function testCancel() { $task = new TestTask(); $pump = $this->getMock('phalanx\\tasks\\TaskPump'); $pump->expects($this->once())->method('Cancel')->with($task); \phalanx\tasks\TaskPump::T_set_pump($pump); $this->assertFalse($task->is_cancelled()); $task->Cancel(); }
public function Fire() { $show = Show::FetchByName($this->input->_id); if (!$show) { TaskPump::Pump()->QueueTask(new ErrorTask('Could not find show named "' . $this->input->_id . '"')); return; } try { $show->Delete(); } catch (\phalanx\data\ModelException $e) { TaskPump::Pump()->QueueTask(new ErrorTask('An error occurred while deleting the show.')); return; } TaskPump::Pump()->QueueTask(new MessageTask('Deleted ' . $show->name)); }
public function Fire() { $show = Show::FetchByName($this->input->_id); if (!$show) { TaskPump::Pump()->QueueTask(new ErrorTask('Could not find show named "' . $this->input->_id . '"')); return; } $show->last_season++; $show->last_episode = 0; try { $show->Update(); } catch (\phalanx\data\ModelException $e) { TaskPump::Pump()->QueueTask(new ErrorTask('An error occurred while updating the record.')); return; } TaskPump::Pump()->QueueTask(new MessageTask('Updated ' . $show->name . ' to ' . $show->last_season . 'x' . $show->last_episode)); }
protected function _DoStart() { if (TaskPump::Pump()->GetTaskHistory()->Count() > 0) { $task = TaskPump::Pump()->GetTaskHistory()->Top(); $tpl_name = ''; if ($task instanceof \phalanx\views\CustomViewTask) { $tpl_name = $task->CustomTemplateName(); } else { $loader = $this->template_loader; $tpl_name = $loader(get_class($task)); } $data = $this->GetTaskData($task); $view = new View($tpl_name); $keys = $data->AllKeys(); foreach ($keys as $key) { $view->{$key} = $data->{$key}; } $view->Render(); } }
public function Fire() { $keeper = new BookKeeper(); $provider = GetProvider(); $shows = Show::FetchAll(); foreach ($shows as $show) { LogMessage("Beginning search for {$show->name}"); $results = $provider->SearchForShow($show); foreach ($results as $episode) { // Skip this episode if it's too old. if (!$keeper->ShouldDownloadEpisode($episode)) { LogMessage("Skipping #{$episode->nzbid} '{$episode->title}' because it is too old"); continue; } // We've already downloaded this episode. if ($episode->IsAlreadyDownloaded()) { LogMessage("Skipping #{$episode->nzbid} '{$episode->title}' because it has been downloaded previously"); continue; } TaskPump::Pump()->QueueTask(new DownloadEpisodeTask($episode)); } } }
public function Fire() { $shows = Show::FetchAll(); foreach ($shows as $show) { $episode = $show->GetLatestEpisode(); if (!$episode) { continue; } // This show hasn't been downloaded yet. if ($episode->season > $show->last_season || $episode->season == $show->last_season && $episode->episode > $show->last_episode) { print "{$show->name} has {$show->last_season}x{$show->last_episode} as latest," . " but most recent download is {$episode->season}x{$episode->episode}. Update" . " [Y/n]? "; $fp = fopen('php://stdin', 'r'); $c = fgetc($fp); fclose($fp); if (strtolower($c) == 'y') { $show->last_season = $episode->season; $show->last_episode = $episode->episode; $show->Update(); TaskPump::Pump()->QueueTask(new MessageTask("Updated {$show->name} to {$show->last_season}x{$show->last_episode}")); } } } }
use phalanx\tasks\CLIDispatcher; use phalanx\tasks\CLIOutputHandler; use phalanx\tasks\TaskPump; require './init.php'; require_once PHALANX_ROOT . '/base/functions.php'; require_once PHALANX_ROOT . '/tasks/task_pump.php'; require_once PHALANX_ROOT . '/tasks/cli_dispatcher.php'; require_once PHALANX_ROOT . '/tasks/cli_output_handler.php'; require './tasks/internal/error.php'; require './tasks/internal/message.php'; $dispatcher = new CLIDispatcher($argv); $dispatcher->set_task_loader(function ($name) { $name = str_replace('-', '_', $name); $path = "./tasks/{$name}.php"; if (!file_exists($path)) { TaskPump::Pump()->RunTask(new ErrorTask('Could not load file for task ' . $name)); return; } require_once $path; return '\\nztv\\' . \phalanx\base\UnderscoreToCamelCase($name) . 'Task'; }); $output_handler = new CLIOutputHandler(); TaskPump::Pump()->set_output_handler($output_handler); if (!isset($argv[1])) { Fatal("Commands: add-show set-episode set-url remove-show update-records"); } // Process the inital task. $dispatcher->Start(); // Stop the pump now that all tasks have been run. TaskPump::Pump()->StopPump();
public function Fire() { TaskPump::Pump()->Terminate($this->message . "\n"); }
public function testSharedPump() { // Reset. TaskPump::T_set_pump(NULL); $this->assertNotNull(TaskPump::Pump(), 'Did not create shared pump.'); $this->assertNotSame($this->pump, TaskPump::Pump()); TaskPump::set_pump($this->pump); $this->assertSame($this->pump, TaskPump::Pump()); }
public function testFilteredAction() { $data = new Dictionary('model', 'test_model', 'action', data\ValidatingModelTask::ACTION_FETCH, 'data', 3); ValidatingTestModelValidator::$test = $this; ValidatingTestModelValidator::$filter_return_value = FALSE; $task = new data\ValidatingModelTask($data); TaskPump::Pump()->RunTask($task); $this->assertNotEquals(0, $task->code()); $this->assertEquals(1, count($task->errors())); $this->assertNull($task->record()); }