public function getNextJob() { $query = new Query('\\Octo\\System\\Model\\SystemJob'); $query->select('*')->from('system_job')->order('run_date', 'ASC')->limit(1); if ($query->execute()) { $job = $query->fetch(); if ($job->getRunDate() <= new \DateTime()) { return $job; } } return null; }
/** * Get jobs due to be scheduled. */ public function getJobsToSchedule() { $query = new Query($this->getNamespace('ScheduledJob') . '\\Model\\ScheduledJob', 'read'); $query->select('s.*'); $query->from('scheduled_job', 's'); $query->join('job', 'j', 's.current_job_id = j.id'); $query->where('(j.id IS NULL) OR ((UNIX_TIMESTAMP(NOW()) - UNIX_TIMESTAMP(j.date_updated)) >= s.frequency AND j.status > 1)'); try { $query->execute(); return new ScheduledJobCollection($query->fetchAll()); } catch (PDOException $ex) { throw new StoreException('Could not get ScheduledJob by CurrentJob', 0, $ex); } }
public function getLastEntry($scope) { $query = new Query($this->getNamespace('Log') . '\\Model\\Log', 'read'); $query->select('*')->from('log')->limit(1); $query->where('scope = :scope'); $query->bind(':scope', $scope); $query->order('id', 'DESC'); try { $query->execute(); return $query->fetch(); } catch (PDOException $ex) { throw new StoreException('Could not get Log by Id', 0, $ex); } }
/** * @param $value * @param string $useConnection Connection type to use. * @throws StoreException * @return SystemJob */ public function getById($value, $useConnection = 'read') { if (is_null($value)) { throw new StoreException('Value passed to ' . __FUNCTION__ . ' cannot be null.'); } $query = new Query($this->getNamespace('SystemJob') . '\\Model\\SystemJob', $useConnection); $query->select('*')->from('system_job')->limit(1); $query->where('`id` = :id'); $query->bind(':id', $value); try { $query->execute(); return $query->fetch(); } catch (PDOException $ex) { throw new StoreException('Could not get SystemJob by Id', 0, $ex); } }
/** * @param $value * @param string $useConnection Connection type to use. * @throws StoreException * @return Contact */ public function getByEmail($value, $useConnection = 'read') { if (is_null($value)) { throw new StoreException('Value passed to ' . __FUNCTION__ . ' cannot be null.'); } $query = new Query($this->getNamespace('Contact') . '\\Model\\Contact', $useConnection); $query->select('*')->from('contact')->limit(1); $query->where('`email` = :email'); $query->bind(':email', $value); try { $query->execute(); $result = $query->fetch(); $this->setCache($value, $result); return $result; } catch (PDOException $ex) { throw new StoreException('Could not get Contact by Email', 0, $ex); } }
/** * @param $value * @param string $useConnection Connection type to use. * @throws StoreException * @return Permission */ public function getById($value, $useConnection = 'read') { if (is_null($value)) { throw new StoreException('Value passed to ' . __FUNCTION__ . ' cannot be null.'); } // This is the primary key, so try and get from cache: $cacheResult = $this->getFromCache($value); if (!empty($cacheResult)) { return $cacheResult; } $query = new Query($this->getNamespace('Permission') . '\\Model\\Permission', $useConnection); $query->select('*')->from('permission')->limit(1); $query->where('`id` = :id'); $query->bind(':id', $value); try { $query->execute(); $result = $query->fetch(); $this->setCache($value, $result); return $result; } catch (PDOException $ex) { throw new StoreException('Could not get Permission by Id', 0, $ex); } }