예제 #1
0
 protected function doSchedule($time)
 {
     $db = $this->getPdoConnection();
     if ($time < $_SERVER['REQUEST_TIME'] - 366 * 86400) {
         $time += $_SERVER['REQUEST_TIME'];
     }
     $data = array('task' => $this, 'cookie' => &$_COOKIE, 'session' => class_exists('SESSION', false) ? s::getAll() : array());
     $sql = "INSERT INTO queue (base, data, run_time)\n                VALUES (?,?,?)";
     $db->prepare($sql)->execute(array(p::__BASE__(), serialize($data), $time));
     $id = $db->lastInsertId();
     $this->registerQueue();
     return $id;
 }
예제 #2
0
 protected function pushMail($mailer, &$headers, &$options)
 {
     if (isset($options['testMode'])) {
         $this->testMode = $options['testMode'];
     } else {
         if ($this->testMode) {
             $options['testMode'] = 1;
         }
     }
     $sent = -(int) (bool) (!empty($options['testMode']));
     $archive = (int) (!(empty($options['archive']) && empty($options['testMode'])));
     $time = isset($options['time']) ? $options['time'] : 0;
     if ($time < $_SERVER['REQUEST_TIME'] - 366 * 86400) {
         $time += $_SERVER['REQUEST_TIME'];
     }
     if (!empty($options['attachments']) && is_array($options['attachments'])) {
         $tmpToken = false;
         foreach ($options['attachments'] as &$file) {
             if (is_uploaded_file($file) || PATCHWORK_ZCACHE === substr($file, 0, strlen(PATCHWORK_ZCACHE))) {
                 $tmpToken || ($tmpToken = p::strongId(8));
                 $base = PATCHWORK_ZCACHE . p::strongId(8) . '~' . $tmpToken;
                 copy($file, $base);
                 $file = $base;
             }
         }
         unset($file, $options['attachments.tmpToken']);
         $tmpToken && ($options['attachments.tmpToken'] = $tmpToken);
     }
     $data = array('mailer' => $mailer, 'headers' => &$headers, 'options' => &$options, 'cookie' => &$_COOKIE, 'session' => class_exists('SESSION', false) ? s::getAll() : array());
     $db = $this->getPdoConnection();
     $sql = "INSERT INTO queue (base, data, send_time, archive, sent_time)\n                VALUES (?,?,?,?,?)";
     $db->prepare($sql)->execute(array(p::__BASE__(), serialize($data), $time, $archive, $sent));
     $sql = $db->lastInsertId();
     $this->registerQueue();
     return $sql;
 }
예제 #3
0
 protected function doOne($id)
 {
     $db = $this->db;
     $sql = "SELECT data FROM queue WHERE rowid={$id} AND run_time=0";
     $data = $db->query($sql)->fetchAll(PDO::FETCH_NUM);
     if (!$data) {
         return;
     }
     $data_serialized = $data[0][0];
     $data = unserialize($data_serialized);
     $this->restoreContext($data['cookie'], $data['session']);
     try {
         try {
             if (0 < ($time = (int) $data['task']->getNextRun())) {
                 $sql = time();
                 if ($time < $sql - 366 * 86400) {
                     $time += $sql;
                 }
                 $sql = "UPDATE queue SET run_time={$time} WHERE rowid={$id}";
                 $db->exec($sql);
             }
         } catch (Exception $e) {
             $data['task']->run();
             throw $e;
         }
         $data['task']->run();
     } catch (Exception $e) {
         echo "Exception on pTask #{$id}:\n\n";
         print_r($e);
         $time = false;
     }
     if ($time > 0) {
         $data['session'] = class_exists('SESSION', false) ? s::getAll() : array();
         if ($data_serialized !== ($data = serialize($data))) {
             $sql = "UPDATE queue SET data=? WHERE rowid=?";
             $db->prepare($sql)->execute(array($data, $id));
         }
     } else {
         if (false !== $time) {
             $sql = "DELETE FROM queue WHERE rowid={$id}";
             $db->exec($sql);
         }
     }
 }
 static function read($id)
 {
     $_SESSION = SESSION::getAll();
     self::$id = $id;
     return '';
 }