/**
  * @param InputSeenEvent $event
  */
 public function onInputSeen(InputSeenEvent $event)
 {
     $inputStatus = $event->getInputStatus();
     $input = InputQuery::create()->findOneByUuid($inputStatus->uuid);
     // This should definitely never happen
     if ($input === null) {
         return;
     }
     if (!$this->_inputErrorCollection->contains($input)) {
         $this->_inputErrorCollection->attach($input, new InputErrorCumulative());
     }
     /* @var InputErrorCumulative $inputErrors */
     $inputErrors = $this->_inputErrorCollection[$input];
     $inputErrors->accumulate($inputStatus);
 }
 /**
  * Get the associated ChildInput object
  *
  * @param  ConnectionInterface $con Optional Connection object.
  * @return ChildInput The associated ChildInput object.
  * @throws PropelException
  */
 public function getInput(ConnectionInterface $con = null)
 {
     if ($this->aInput === null && ($this->input_uuid !== "" && $this->input_uuid !== null)) {
         $this->aInput = ChildInputQuery::create()->findPk($this->input_uuid, $con);
         /* The following can be used additionally to
               guarantee the related object contains a reference
               to this object.  This level of coupling may, however, be
               undesirable since it could result in an only partially populated collection
               in the referenced object.
               $this->aInput->addInputErrors($this);
            */
     }
     return $this->aInput;
 }
 /**
  * Returns a new ChildInputQuery object.
  *
  * @param     string $modelAlias The alias of a model in the query
  * @param     Criteria $criteria Optional Criteria to build the query from
  *
  * @return ChildInputQuery
  */
 public static function create($modelAlias = null, Criteria $criteria = null)
 {
     if ($criteria instanceof ChildInputQuery) {
         return $criteria;
     }
     $query = new ChildInputQuery();
     if (null !== $modelAlias) {
         $query->setModelAlias($modelAlias);
     }
     if ($criteria instanceof Criteria) {
         $query->mergeWith($criteria);
     }
     return $query;
 }
 /**
  * Returns the number of related Input objects.
  *
  * @param      Criteria $criteria
  * @param      boolean $distinct
  * @param      ConnectionInterface $con
  * @return int             Count of related Input objects.
  * @throws PropelException
  */
 public function countInputs(Criteria $criteria = null, $distinct = false, ConnectionInterface $con = null)
 {
     $partial = $this->collInputsPartial && !$this->isNew();
     if (null === $this->collInputs || null !== $criteria || $partial) {
         if ($this->isNew() && null === $this->collInputs) {
             return 0;
         }
         if ($partial && !$criteria) {
             return count($this->getInputs());
         }
         $query = ChildInputQuery::create(null, $criteria);
         if ($distinct) {
             $query->distinct();
         }
         return $query->filterByInstance($this)->count($con);
     }
     return count($this->collInputs);
 }
 /**
  * Performs an INSERT on the database, given a Input or Criteria object.
  *
  * @param mixed               $criteria Criteria or Input object containing data that is used to create the INSERT statement.
  * @param ConnectionInterface $con the ConnectionInterface connection to use
  * @return mixed           The new primary key.
  * @throws PropelException Any exceptions caught during processing will be
  *                         rethrown wrapped into a PropelException.
  */
 public static function doInsert($criteria, ConnectionInterface $con = null)
 {
     if (null === $con) {
         $con = Propel::getServiceContainer()->getWriteConnection(InputTableMap::DATABASE_NAME);
     }
     if ($criteria instanceof Criteria) {
         $criteria = clone $criteria;
         // rename for clarity
     } else {
         $criteria = $criteria->buildCriteria();
         // build Criteria from Input object
     }
     // Set the correct dbName
     $query = InputQuery::create()->mergeWith($criteria);
     // use transaction because $criteria could contain info
     // for more than one table (I guess, conceivably)
     return $con->transaction(function () use($con, $query) {
         return $query->doInsert($con);
     });
 }
 /**
  * Builds a Criteria object containing the primary key for this object.
  *
  * Unlike buildCriteria() this method includes the primary key values regardless
  * of whether or not they have been modified.
  *
  * @throws LogicException if no primary key is defined
  *
  * @return Criteria The Criteria object containing value(s) for primary key(s).
  */
 public function buildPkeyCriteria()
 {
     $criteria = ChildInputQuery::create();
     $criteria->add(InputTableMap::COL_UUID, $this->uuid);
     return $criteria;
 }
 /**
  * @param SubscriptionSeenEvent $event
  *
  * @throws \Propel\Runtime\Exception\PropelException
  */
 public function onSubscriptionSeen(SubscriptionSeenEvent $event)
 {
     $instanceName = $event->getInstance();
     $status = $event->getSubscription();
     // Ignore certain subscriptions
     if (in_array($status->getType(), [SubscriptionStatus::TYPE_EPGGRAB, SubscriptionStatus::TYPE_SERVICE_OR_MUX])) {
         return;
     }
     // Determine the username to store for the subscription
     $username = $status->username;
     switch ($status->getType()) {
         case SubscriptionStatus::TYPE_RECORDING:
             $username = User::NAME_DVR;
             break;
     }
     // Get the instance, user and channel
     $instance = InstanceQuery::create()->findPk($instanceName);
     $user = UserQuery::create()->filterByInstance($instance)->filterByName($username)->findOne();
     // Ensure the channel exists
     $this->onChannelSeen($instanceName, $status->channel);
     $channel = ChannelQuery::create()->filterByInstance($instance)->filterByName($status->channel)->findOne();
     if (SubscriptionQuery::create()->hasSubscription($instance, $user, $channel, $status)) {
         return;
     }
     // Try to determine which input is used by the subscription
     $input = InputQuery::create()->filterBySubscriptionStatus($instanceName, $status)->findOne();
     if ($input === null) {
         $this->logger->warning('Got subscription that cannot be tied to an input ({instanceName}, user: {userName}, channel: {channelName})', ['instanceName' => $instanceName, 'userName' => $user !== null ? $user->getName() : 'N/A', 'channelName' => $channel->getName()]);
     }
     $subscription = new Subscription();
     $subscription->setInstance($instance)->setInput($input)->setUser($user)->setChannel($channel)->setSubscriptionId($status->id)->setStarted($status->start)->setTitle($status->title)->setService($status->service);
     $subscription->save();
     $this->logger->info('Stored new subscription (instance: {instanceName}, user: {userName}, channel: {channelName})', ['instanceName' => $instanceName, 'userName' => $user !== null ? $user->getName() : 'N/A', 'channelName' => $channel->getName()]);
 }