/** * Validate that the file plugin factory sets the browser flag on the * appropriate file plugin */ public function test_filepluginfactorysetsbrowserflag() { global $CFG; require_once $CFG->dirroot . '/local/datahub/lib/rlip_fileplugin.class.php'; // Setup. $fileplugin = rlip_fileplugin_factory::factory('', null, false, true); // Validation. $this->assertEquals($fileplugin->sendtobrowser, true); }
/** * Hook for providing a file plugin for a particular * import entity type * * @param string $entity The type of entity * @return object The file plugin instance, or false if not applicable */ function get_import_file($entity) { global $CFG; require_once $CFG->dirroot . '/local/datahub/lib/rlip_fileplugin.class.php'; foreach ($this->entity_types as $key => $value) { if ($entity == $value) { if ($this->fileids[$key] !== false) { return rlip_fileplugin_factory::factory('', $this->fileids[$key]); } } } return false; }
/** * Provides the object used to log information to the file system logfile * * @param string $plugin the plugin * @param string $entity the entity type * @param boolean $manual Set to true if a manual run * @param integer $starttime the time used in the filename * @return object the fslogger */ function get_fslogger($plugin, $entity = '', $manual = false, $starttime = 0) { global $CFG; require_once $CFG->dirroot . '/local/datahub/lib/rlip_fslogger.class.php'; //set up the file-system logger $filepath = get_config($plugin, 'logfilelocation'); //get filename $filename = rlip_log_file_name('import', $plugin, $filepath, $entity, $manual, $starttime); if (!empty($filename)) { $this->set_log_path($filename); $fileplugin = rlip_fileplugin_factory::factory($filename, NULL, true); return rlip_fslogger_factory::factory($plugin, $fileplugin, $manual); } return null; }
/** * Provides a file-system logger object bound to a log file * * @param boolean $manual true to indicate to the logger that the run is * manual, or false for scheduled * @return array Array of the logger object and the associated filename */ protected function get_fs_logger($manual = false) { global $CFG; set_config('logfilelocation', $CFG->dataroot, 'bogus_plugin'); // Set up the file plugin for IO. $filename = $CFG->dataroot . '/rliptest.log'; $fileplugin = rlip_fileplugin_factory::factory($filename, null, true); // Set up the logging object. $fslogger = rlip_fslogger_factory::factory('bogus_plugin', $fileplugin, $manual); return array($fslogger, $filename); }
/** * sub-function for running scheduled IP jobs * * @param string $prefix mtrace prefix string * @param string $plugin The plugin name * @param string $type The plugin type (i.e. dhimport, dhexport) * @param int $userid the scheduled job's Moodle userid * @param object $state the scheduled job's past state object * @uses $CFG * @uses $DB * @return object import/export instance to run, null on error (for unsupported plugin) */ function rlip_get_run_instance($prefix, $plugin, $type, $userid, $state) { global $CFG, $DB; $instance = null; $rlipshortname = 'DH'; switch ($type) { // TBD case 'dhimport': $baseinstance = rlip_dataplugin_factory::factory($plugin); $entity_types = $baseinstance->get_import_entities(); $files = array(); $dataroot = rtrim($CFG->dataroot, DIRECTORY_SEPARATOR); $path = $dataroot . DIRECTORY_SEPARATOR . trim(get_config($plugin, 'schedule_files_path'), DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR; $temppath = sprintf($dataroot . RLIP_IMPORT_TEMPDIR, $plugin); if (!file_exists($temppath) && !@mkdir($temppath, 0777, true)) { mtrace("{$prefix}: Error creating directory '{$temppath}' ... using '{$path}'"); //TBD*** just use main directory??? $temppath = $path; } foreach ($entity_types as $entity) { $entity_filename = get_config($plugin, $entity . '_schedule_file'); if (empty($entity_filename)) { // TBD: need dummy so we're not testing directories! $entity_filename = $entity . '.csv'; } //echo "\n get_config('{$plugin}', '{$entity}_schedule_file') => {$entity_filename}"; if ($state == null && $path !== $temppath && file_exists($path . $entity_filename) && !@rename($path . $entity_filename, $temppath . $entity_filename)) { $message = "{$prefix}: Error moving '" . $path . $entity_filename . "' to '" . $temppath . $entity_filename . "'"; mtrace($message); continue; // Let's skip any unmovable files. } $files[$entity] = $temppath . $entity_filename; } $importprovider = new rlip_importprovider_csv($entity_types, $files); $instance = rlip_dataplugin_factory::factory($plugin, $importprovider); break; case 'dhexport': $tz = $DB->get_field('user', 'timezone', array('id' => $userid)); $export = rlip_get_export_filename($plugin, $tz === false ? 99 : $tz); $fileplugin = rlip_fileplugin_factory::factory($export, NULL, false); $instance = rlip_dataplugin_factory::factory($plugin, NULL, $fileplugin); break; default: mtrace("{$prefix}: {$rlipshortname} plugin '{$plugin}' not supported!"); break; } return $instance; }
/** * Hook for providing a file plugin for a particular * import entity type * * @param string $entity The type of entity * @return object The file plugin instance, or false if not applicable */ public function get_import_file($entity) { if ($entity != 'user') { return false; } return rlip_fileplugin_factory::factory($this->filename); }
/** * Valid fslogger required for phpunit tests * @param string $plugin * @param string $entity the entity type * @param boolean $manual Set to true if a manual run * @param integer $starttime the time used in the filename * @return object The fslogger instance */ public function get_fslogger($plugin, $entity = '', $manual = false, $starttime = 0) { $fileplugin = rlip_fileplugin_factory::factory('/dev/null', null, true); $entity = ''; return rlip_fslogger_factory::factory($plugin, $fileplugin, $entity); }
$plugin = required_param('plugin', PARAM_CLEAN); // Need base URL for form and Moodle block management $baseurl = $CFG->wwwroot . '/local/datahub/exportplugins/manualrun.php?plugin=' . $plugin; //page setup $plugin_display = get_string('pluginname', $plugin); rlip_manualrun_page_setup($baseurl, $plugin_display); //javascript library needed by the form $PAGE->requires->js('/local/datahub/js/lib.js'); //create our basic form $form = new rlip_manualexport_form(); $form->set_data(array('plugin' => $plugin)); //run the export before printing a page header if ($data = $form->get_data()) { //run the export $filename = rlip_get_export_filename($plugin, $USER->timezone); $fileplugin = rlip_fileplugin_factory::factory($filename, NULL, false, true); //indicate to the factory class that this is a manual run $manual = true; $instance = rlip_dataplugin_factory::factory($plugin, NULL, $fileplugin, $manual); ob_start(); $result = $instance->run(0, 0, rlip_get_maxruntime()); $errors = ob_get_contents(); ob_end_clean(); if ($result !== null) { // Error running export (probably time limit exceeded) echo $OUTPUT->header(); //display errors in a span so we can clear it using javascript when needed $attributes = array('id' => 'rlipexporterrors'); echo html_writer::tag('span', $errors, $attributes); //display the form $form->display();
/** * Default export plugin constructor * * @param object $fileplugin the file plugin used for output * @param boolean $manual Set to true if a manual run */ function __construct($fileplugin, $manual = false) { global $CFG; require_once $CFG->dirroot . '/local/datahub/lib/rlip_dblogger.class.php'; require_once $CFG->dirroot . '/local/datahub/lib/rlip_fslogger.class.php'; $this->fileplugin = $fileplugin; $this->manual = $manual; $this->dblogger = new rlip_dblogger_export($this->manual); //convert class name to plugin name $class = get_class($this); $this->plugin = str_replace('rlip_exportplugin_', 'dhexport_', $class); //track the start time as the current time - moved from run() in order to support rlip_log_file_name $this->dblogger->set_starttime(time()); //set up the file-system logger, if exists $filepath = get_config($this->plugin, 'logfilelocation'); $filename = rlip_log_file_name('export', $this->plugin, $filepath, '', $manual, $this->dblogger->starttime); if (!empty($filename)) { $this->dblogger->set_log_path($filename); $fileplugin = rlip_fileplugin_factory::factory($filename, NULL, true, $manual); $this->fslogger = rlip_fslogger_factory::factory($this->plugin, $fileplugin, $this->manual); } $this->dblogger->set_plugin($this->plugin); }