/** * Test for the clear method (clearing each query type). * * @return void * * @covers JDatabaseQuery::clear * @since 11.1 */ public function testClear_type() { $types = array( 'select', 'delete', 'update', 'insert', 'union', ); $clauses = array( 'from', 'join', 'set', 'where', 'group', 'having', 'order', 'columns', 'values', ); // Set the clauses. foreach ($clauses as $clause) { $this->_instance->$clause = $clause; } // Check that all properties have been cleared foreach ($types as $type) { // Set the type. $this->_instance->$type = $type; // Clear the type. $this->_instance->clear($type); // Check the type has been cleared. $this->assertThat( $this->_instance->type, $this->equalTo(null) ); $this->assertThat( $this->_instance->get($type), $this->equalTo(null) ); // Now check the claues have not been affected. foreach ($clauses as $clause) { $this->assertThat( $this->_instance->get($clause), $this->equalTo($clause) ); } } }
/** * Clear data from the query or a specific clause of the query. * * @param string $clause Optionally, the name of the clause to clear, or nothing to clear the whole query. * * @return void * * @since 11.3 */ public function clear($clause = null) { switch ($clause) { case 'limit': $this->limit = null; break; case 'offset': $this->offset = null; break; case 'forUpdate': $this->forUpdate = null; break; case 'forShare': $this->forShare = null; break; case 'noWait': $this->noWait = null; break; case 'returning': $this->returning = null; break; case 'select': case 'update': case 'delete': case 'insert': case 'from': case 'join': case 'set': case 'where': case 'group': case 'having': case 'order': case 'columns': case 'values': parent::clear($clause); break; default: $this->type = null; $this->limit = null; $this->offset = null; $this->forUpdate = null; $this->forShare = null; $this->noWait = null; $this->returning = null; parent::clear($clause); break; } return $this; }
/** * Run all active cron jobs * * @return void */ protected function doCron() { $app = JFactory::getApplication(); $mailer = JFactory::getMailer(); $config = JFactory::getConfig(); $input = $app->input; if ($app->isAdmin() || $input->get('option') == 'com_acymailing') { return; } // $$$ hugh - don't want to run on things like AJAX calls if ($input->get('format', '') == 'raw') { return; } // Get all active tasks $this->db = FabrikWorker::getDbo(true); $this->query = $this->db->getQuery(true); $now = $input->get('fabrikcron_run', false); $this->log = FabTable::getInstance('Log', 'FabrikTable'); if (!$now) { /* $$$ hugh - changed from using NOW() to JFactory::getDate(), to avoid time zone issues, see: * http://fabrikar.com/forums/showthread.php?p=102245#post102245 * .. which seems reasonable, as we use getDate() to set 'lastrun' to at the end of this func */ $nextRun = "CASE " . "WHEN unit = 'second' THEN DATE_ADD( lastrun, INTERVAL frequency SECOND )\n" . "WHEN unit = 'minute' THEN DATE_ADD( lastrun, INTERVAL frequency MINUTE )\n" . "WHEN unit = 'hour' THEN DATE_ADD( lastrun, INTERVAL frequency HOUR )\n" . "WHEN unit = 'day' THEN DATE_ADD( lastrun, INTERVAL frequency DAY )\n" . "WHEN unit = 'week' THEN DATE_ADD( lastrun, INTERVAL frequency WEEK )\n" . "WHEN unit = 'month' THEN DATE_ADD( lastrun, INTERVAL frequency MONTH )\n" . "WHEN unit = 'year' THEN DATE_ADD( lastrun, INTERVAL frequency YEAR ) END"; $this->query->select("id, plugin, lastrun, unit, frequency, " . $nextRun . " AS nextrun")->from('#__{package}_cron')->where("published = '1'")->where("{$nextRun} < '" . JFactory::getDate()->toSql() . "'"); } else { $this->query->select('id, plugin')->from("#__{package}_cron WHERE published = '1'"); } $this->db->setQuery($this->query); $rows = $this->db->loadObjectList(); if (empty($rows)) { return; } // register our shutdownHandler(), so we can re-publish and reschedule the event if the script errors out register_shutdown_function(array($this, 'shutdownHandler')); $this->log->message = ''; JModelLegacy::addIncludePath(JPATH_SITE . '/components/com_fabrik/models'); /** @var FabrikFEModelPluginmanager $pluginManager */ $pluginManager = JModelLegacy::getInstance('Pluginmanager', 'FabrikFEModel'); $listModel = JModelLegacy::getInstance('list', 'FabrikFEModel'); foreach ($rows as $row) { // assign $row to $this->row, as we may need it in shutdown handling $this->row = $row; // Load in the plugin $this->pluginModel = $pluginManager->getPluginFromId($this->row->id, 'Cron'); $params = $this->pluginModel->getParams(); $this->log->message = ''; $this->log->id = null; $this->log->referring_url = ''; $this->log->message_type = 'plg.cron.' . $this->row->plugin; if (!$this->pluginModel->queryStringActivated()) { continue; } if ($this->pluginModel->doRunGating()) { $this->query->clear()->update('#__{package}_cron')->set('published = 0')->where('id = ' . $this->db->quote($this->row->id)); $this->db->setQuery($this->query); $this->db->execute(); } $tid = (int) $params->get('table'); $thisListModel = clone $listModel; if ($tid !== 0) { $thisListModel->setId($tid); $this->log->message .= "\n\n" . $this->row->plugin . "\n listid = " . $thisListModel->getId(); if ($this->pluginModel->requiresTableData()) { //$table = $thisListModel->getTable(); //$total = $thisListModel->getTotalRecords(); //$nav = $thisListModel->getPagination($total, 0, $total); $cron_row_limit = (int) $params->get('cron_row_limit', 100); $thisListModel->setLimits(0, $cron_row_limit); $thisListModel->getPagination(0, 0, $cron_row_limit); $data = $thisListModel->getData(); // for some reason this hoses up next query //$this->log->message .= "\n" . $thisListModel->buildQuery(); } } else { $data = array(); } $this->pluginModel->process($data, $thisListModel); $this->log->message = $this->pluginModel->getLog() . "\n\n" . $this->log->message; $this->reschedule(); // Log if asked for if ($params->get('log', 0) == 1) { $this->log->store(); } // Email log message $recipient = explode(',', $params->get('log_email', '')); if (!FArrayHelper::emptyish($recipient)) { $subject = $config->get('sitename') . ': ' . $this->row->plugin . ' scheduled task'; $mailer->sendMail($config->get('mailfrom'), $config->get('fromname'), $recipient, $subject, $this->log->message, true); } } }