You are here

public function Subscription::setSubscription in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 vendor/zendframework/zend-feed/src/PubSubHubbub/Model/Subscription.php \Zend\Feed\PubSubHubbub\Model\Subscription::setSubscription()

Save subscription to RDMBS

Parameters

array $data:

Return value

bool

Throws

PubSubHubbub\Exception\InvalidArgumentException

Overrides SubscriptionPersistenceInterface::setSubscription

File

vendor/zendframework/zend-feed/src/PubSubHubbub/Model/Subscription.php, line 32

Class

Subscription

Namespace

Zend\Feed\PubSubHubbub\Model

Code

public function setSubscription(array $data) {
  if (!isset($data['id'])) {
    throw new PubSubHubbub\Exception\InvalidArgumentException('ID must be set before attempting a save');
  }
  $result = $this->db
    ->select([
    'id' => $data['id'],
  ]);
  if ($result && 0 < count($result)) {
    $data['created_time'] = $result
      ->current()->created_time;
    $now = $this
      ->getNow();
    if (array_key_exists('lease_seconds', $data) && $data['lease_seconds']) {
      $data['expiration_time'] = $now
        ->add(new DateInterval('PT' . $data['lease_seconds'] . 'S'))
        ->format('Y-m-d H:i:s');
    }
    $this->db
      ->update($data, [
      'id' => $data['id'],
    ]);
    return false;
  }
  $this->db
    ->insert($data);
  return true;
}