/**
  * Adds fields on this event to a query being prepared to go into the database
  * @param JDatabaseQuery &$query Query being prepared. Modified in place.
  */
 public function toDatabase(JDatabaseQuery &$query)
 {
     foreach ($this->dbmappings as $var => $dbField) {
         if (isset($this->{$var})) {
             $query->set($dbField . " = '" . $query->escape($this->{$var}) . "'");
         }
     }
 }
示例#2
0
 /**
  * Reschedule the plugin for next run, and republish
  *
  *
  * @return void
  */
 protected function reschedule()
 {
     $now = JFactory::getDate();
     $now = $now->toUnix();
     $new = JFactory::getDate($this->row->nextrun);
     $tmp = $new->toUnix();
     switch ($this->row->unit) {
         case 'second':
             $inc = 1;
             break;
         case 'minute':
             $inc = 60;
             break;
         case 'hour':
             $inc = 60 * 60;
             break;
         default:
         case 'day':
             $inc = 60 * 60 * 24;
             break;
     }
     while ($tmp + $inc * $this->row->frequency < $now) {
         $tmp = $tmp + $inc * $this->row->frequency;
     }
     // Mark them as being run
     $nextRun = JFactory::getDate($tmp);
     $this->query->clear();
     $this->query->update('#__{package}_cron');
     $this->query->set('lastrun = ' . $this->db->quote($nextRun->toSql()));
     if ($this->pluginModel->shouldReschedule() && $this->pluginModel->doRunGating()) {
         $this->query->set("published = '1'");
     }
     if (!$this->pluginModel->shouldReschedule()) {
         $this->query->set("published = '0'");
         $this->log->message .= "\nPlugin has unpublished itself";
     }
     $this->query->where('id = ' . $this->row->id);
     $this->db->setQuery($this->query);
     $this->db->execute();
 }
 /**
  * Tests the JDatabaseQuery::set method.
  *
  * @return  void
  *
  * @covers  JDatabaseQuery::set
  * @since   11.3
  */
 public function testSet()
 {
     $this->assertThat($this->_instance->set('foo = 1'), $this->identicalTo($this->_instance), 'Tests chaining.');
     $this->assertEquals('SET foo = 1', trim(TestReflection::getValue($this->_instance, 'set')), 'Tests set with a string.');
     $this->_instance->set('bar = 2');
     $this->assertEquals("SET foo = 1\n\t, bar = 2", trim(TestReflection::getValue($this->_instance, 'set')), 'Tests appending with set().');
     // Clear the set.
     TestReflection::setValue($this->_instance, 'set', null);
     $this->_instance->set(array('foo = 1', 'bar = 2'));
     $this->assertEquals("SET foo = 1\n\t, bar = 2", trim(TestReflection::getValue($this->_instance, 'set')), 'Tests set with an array.');
     // Clear the set.
     TestReflection::setValue($this->_instance, 'set', null);
     $this->_instance->set(array('foo = 1', 'bar = 2'), ';');
     $this->assertEquals("SET foo = 1\n\t; bar = 2", trim(TestReflection::getValue($this->_instance, 'set')), 'Tests set with an array and glue.');
 }
 /**
  * Tests the JDatabaseQuery::set method.
  *
  * @return  void
  *
  * @covers  JDatabaseQuery::set
  * @since   11.3
  */
 public function testSet()
 {
     $this->assertThat($this->_instance->set('foo = 1'), $this->identicalTo($this->_instance), 'Tests chaining.');
     $this->assertThat(trim($this->_instance->set), $this->identicalTo('SET foo = 1'), 'Tests set with a string.');
     $this->_instance->set('bar = 2');
     $this->assertEquals("SET foo = 1" . PHP_EOL . "\t, bar = 2", trim($this->_instance->set), 'Tests appending with set().');
     // Clear the set.
     $this->_instance->set = null;
     $this->_instance->set(array('foo = 1', 'bar = 2'));
     $this->assertThat(trim($this->_instance->set), $this->identicalTo("SET foo = 1" . PHP_EOL . "\t, bar = 2"), 'Tests set with an array.');
     // Clear the set.
     $this->_instance->set = null;
     $this->_instance->set(array('foo = 1', 'bar = 2'), ';');
     $this->assertThat(trim($this->_instance->set), $this->identicalTo("SET foo = 1" . PHP_EOL . "\t; bar = 2"), 'Tests set with an array and glue.');
 }
 public function toDatabase(JDatabaseQuery &$query)
 {
     $query->set("on_date = '" . $query->escape(strftime("%Y-%m-%d", $this->start)) . "'");
     if (date("Hi", $this->start) != 0) {
         $query->set("starttime = '" . $query->escape(strftime("%H:%M", $this->start)) . "'");
     } else {
         $query->set("starttime = NULL");
     }
     if (!empty($this->end)) {
         $query->set("endtime = '" . $query->escape(strftime("%H:%M", $this->end)) . "'");
     } else {
         $query->set("endtime = NULL");
     }
     if (!empty($this->newMemberStart)) {
         $query->set("newmemberstart = '" . $query->escape(strftime("%H:%M", $this->newMemberStart)) . "'");
     } else {
         $query->set("newmemberstart = NULL");
     }
     if (!empty($this->newMemberEnd)) {
         $query->set("newmemberend = '" . $query->escape(strftime("%H:%M", $this->newMemberEnd)) . "'");
     } else {
         $query->set("newmemberend = NULL");
     }
     $query->set("version = " . $this->alterations->version);
     $query->set("lastmodified = '" . $query->escape($this->alterations->lastModified) . "'");
     $query->set('detailsaltered = ' . (int) $this->alterations->details);
     $query->set('cancelled = ' . (int) $this->alterations->cancelled);
     $query->set('placetimealtered = ' . (int) $this->alterations->placeTime);
     $query->set('organiseraltered = ' . (int) $this->alterations->organiser);
     $query->set('datealtered = ' . (int) $this->alterations->date);
     if (!empty($this->latLng)) {
         $query->set("latitude = " . $this->latLng->lat);
         $query->set("longitude = " . $this->latLng->lng);
     } else {
         $query->set("latitude = NULL");
         $query->set("longitude = NULL");
     }
     parent::toDatabase($query);
 }