function fake_cron_register_task($params) { if (!isset($params['name'])) { throw new Exception('Task Name must be provided for fake cron tasks'); } if (!isset($params['plugin_class'])) { throw new Exception('plugin_class must be provided for fake cron tasks'); } if (!class_exists($params['plugin_class'])) { $class = $params['plugin_class']; throw new Exception("Class {$class} for FakeCron does not exist."); } if (!isset($params['interval'])) { throw new Exception('Interval for FakeCron Task must be set.'); } if (!isset($params['plugin_name'])) { throw new Exception('Plugin Name for FakeCron Task must be set.'); } $newTask = new FakeCron_Task(); $newTask->name = $params['name']; if (isset($params['description'])) { $newTask->description = $params['description']; } if (isset($params['plugin_name'])) { $newTask->plugin_name = $params['plugin_name']; } $newTask->plugin_name = $params['plugin_name']; $newTask->plugin_class = $params['plugin_class']; $newTask->interval = $params['interval']; $newTask->save(); }
public function addAction() { require_once PLUGIN_DIR . "/FeedImporter/libraries/SimplePie/simplepie.inc"; $feed = new SimplePie(); $varName = strtolower($this->_modelClass); $class = $this->_modelClass; $record = new FeedImporter_Feed(); //Need an id to work with the tags, so save it now, even though it might be sloppy/confusing $record->save(); if ($_GET['feed_url']) { $feed_url = $_GET['feed_url']; $debug = new stdClass(); $feed->set_feed_url($feed_url); // Run SimplePie. $feed->init(); $feed->handle_content_type(); if ($feed->error()) { $this->flash($feed->error()); //return here? } $debug->title = $feed->get_title(); $debug->description = $feed->get_description(); //Set up the tag configurations for the first import $import = new FeedImporter_Import(); $import->processFeedTags($feed, $record->id); $record->feed_url = $feed_url; $record->feed_title = $feed->get_title(); $record->feed_description = $feed->get_description(); } $record->save(); // Create a new FakeCron_Task for the feed $fc_task = new FakeCron_Task(); $fc_task->interval = 0; $fc_task->name = "Cron for feed " . $record->feed_title; $fc_task->plugin_class = "FeedImporter_FakeCronTask"; $fc_task->plugin_name = 'FeedImporter'; $fc_task->params = serialize(array($record->id)); $fc_task->save(); $record->task_id = $fc_task->id; $_POST['task_id'] = $fc_task->id; $this->view->assign(array($varName => $record)); try { if ($record->saveForm($_POST)) { $this->redirect->goto('browse'); } } catch (Omeka_Validator_Exception $e) { $this->flashValidationErrors($e); } catch (Exception $e) { $this->flash($e->getMessage()); } }