Example #1
0
 /**
  * Will call events as close as it gets to one hour. Event handlers
  * which use this MUST be as quick as possible, maybe only adding a
  * queue item to be handled later or something. Otherwise execution
  * will timeout for PHP - or at least cause unnecessary delays for
  * the unlucky user who visits the site exactly at one of these events.
  */
 public function callTimedEvents()
 {
     $timers = array('minutely' => 60, 'hourly' => 3600, 'daily' => 86400, 'weekly' => 604800);
     foreach ($timers as $name => $interval) {
         $run = false;
         $lastrun = new Config();
         $lastrun->section = 'cron';
         $lastrun->setting = 'last_' . $name;
         $found = $lastrun->find(true);
         if (!$found) {
             $lastrun->value = time();
             if ($lastrun->insert() === false) {
                 common_log(LOG_WARNING, "Could not save 'cron' setting '{$name}'");
                 continue;
             }
             $run = true;
         } elseif ($lastrun->value < time() - $interval) {
             $orig = clone $lastrun;
             $lastrun->value = time();
             $lastrun->update($orig);
             $run = true;
         }
         if ($run === true) {
             // such as CronHourly, CronDaily, CronWeekly
             Event::handle('Cron' . ucfirst($name));
         }
     }
 }
Example #2
0
 static function save($section, $setting, $value)
 {
     $result = null;
     $config = Config::pkeyGet(array('section' => $section, 'setting' => $setting));
     if (!empty($config)) {
         $orig = clone $config;
         $config->value = $value;
         $result = $config->update($orig);
     } else {
         $config = new Config();
         $config->section = $section;
         $config->setting = $setting;
         $config->value = $value;
         $result = $config->insert();
     }
     return $result;
 }
Example #3
0
 /**
  * Test
  *
  * @return void
  */
 public function testSetValue()
 {
     $this->object->insert(array('identifier' => 'string_identifier', 'value' => 'string_result_insert_value'));
     $this->assertTrue((bool) $this->object->setValue('string_identifier', 'string_result_insert_new_value'));
     $this->object->delete(array('identifier' => 'string_identifier'));
 }