Esempio n. 1
0
 /**
  * Save response to database
  *
  * @param array     $aResponse
  * @param RemoteApp $oRemoteApp
  *
  * @throws \Exception
  *
  * @return void
  */
 private function _saveResponse($aResponse, $oRemoteApp)
 {
     // get model by app-type
     $sClassName = '\\Slashworks\\AppBundle\\Model\\RemoteHistory' . ucfirst($oRemoteApp->getType());
     $sQueryClassName = '\\Slashworks\\AppBundle\\Model\\RemoteHistory' . ucfirst($oRemoteApp->getType() . 'Query');
     // if class exists, proceed...
     if (class_exists($sClassName)) {
         // find histories for remote-app
         $aHistories = $sQueryClassName::create()->findByRemoteAppId($oRemoteApp->getId());
         // create new history-entry
         $oRemoteHistoryClass = new $sClassName();
         $oRemoteHistoryClass->setRemoteApp($oRemoteApp);
         $oRemoteHistoryClass->setData($aResponse);
         // convert created class to array for comparsion
         $aNewHistory = $oRemoteHistoryClass->toArray();
         $aNewHistory['Extensions'] = $aNewHistory['Extensions']->getArrayCopy();
         if (is_object($aNewHistory['Log'])) {
             $aNewHistory['Log'] = $aNewHistory['Log']->getArrayCopy();
         } else {
             $aNewHistory['Log'] = array();
         }
         unset($aNewHistory['Id']);
         // interate old histories and convert to array for comparsion
         foreach ($aHistories as $oHistory) {
             $aHistory = $oHistory->toArray();
             $aHistory['Extensions'] = $aHistory['Extensions']->getArrayCopy();
             if (is_object($aHistory['Log'])) {
                 $aHistory['Log'] = $aHistory['Log']->getArrayCopy();
             } else {
                 $aHistory['Log'] = array();
             }
             unset($aHistory['Id']);
             // if api-call was not successful, send notifiations if configured
             if ($aResponse['statuscode'] != 200) {
                 if ($oRemoteApp->checkNotificationSetting("NotificationError")) {
                     $this->_sendErrorNotification($oRemoteApp, $aResponse);
                 }
             } else {
                 // if api-call was successful, compare old and new history and send differences to user
                 $aNew = $this->arrayRecursiveDiff($aNewHistory, $aHistory);
                 // diff exists?
                 if (!empty($aNew) && $oRemoteApp->checkNotificationSetting("NotificationChange")) {
                     $aOld = $this->arrayRecursiveDiff($aHistory, $aNewHistory);
                     $this->_sendNotification(array('old' => $aOld, 'new' => $aNew), $oRemoteApp, $aNewHistory);
                 }
             }
             // delete old history
             $oHistory->delete();
         }
         // save created history
         $oRemoteHistoryClass->save();
         $oRemoteApp->setLastRun(time());
         $oRemoteApp->save();
     } else {
         throw new \Exception('Class \'' . $sClassName . '\' not found... ');
     }
 }
 /**
  * Exclude object from result
  *
  * @param   RemoteApp $remoteApp Object to remove from the list of results
  *
  * @return RemoteAppQuery The current query, for fluid interface
  */
 public function prune($remoteApp = null)
 {
     if ($remoteApp) {
         $this->addUsingAlias(RemoteAppPeer::ID, $remoteApp->getId(), Criteria::NOT_EQUAL);
     }
     return $this;
 }
 /**
  * Declares an association between this object and a RemoteApp object.
  *
  * @param                  RemoteApp $v
  * @return RemoteHistoryContao The current object (for fluent API support)
  * @throws PropelException
  */
 public function setRemoteApp(RemoteApp $v = null)
 {
     if ($v === null) {
         $this->setRemoteAppId(NULL);
     } else {
         $this->setRemoteAppId($v->getId());
     }
     $this->aRemoteApp = $v;
     // Add binding for other direction of this n:n relationship.
     // If this object has already been added to the RemoteApp object, it will not be re-added.
     if ($v !== null) {
         $v->addRemoteHistoryContao($this);
     }
     return $this;
 }
 /**
  * Filter the query by a related RemoteApp object
  *
  * @param   RemoteApp|PropelObjectCollection $remoteApp The related object(s) to use as filter
  * @param     string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
  *
  * @return                 ApiLogQuery The current query, for fluid interface
  * @throws PropelException - if the provided filter is invalid.
  */
 public function filterByRemoteApp($remoteApp, $comparison = null)
 {
     if ($remoteApp instanceof RemoteApp) {
         return $this->addUsingAlias(ApiLogPeer::REMOTE_APP_ID, $remoteApp->getId(), $comparison);
     } elseif ($remoteApp instanceof PropelObjectCollection) {
         if (null === $comparison) {
             $comparison = Criteria::IN;
         }
         return $this->addUsingAlias(ApiLogPeer::REMOTE_APP_ID, $remoteApp->toKeyValue('PrimaryKey', 'Id'), $comparison);
     } else {
         throw new PropelException('filterByRemoteApp() only accepts arguments of type RemoteApp or PropelCollection');
     }
 }
 /**
  * Adds an object to the instance pool.
  *
  * Propel keeps cached copies of objects in an instance pool when they are retrieved
  * from the database.  In some cases -- especially when you override doSelect*()
  * methods in your stub classes -- you may need to explicitly add objects
  * to the cache in order to ensure that the same objects are always returned by doSelect*()
  * and retrieveByPK*() calls.
  *
  * @param RemoteApp $obj A RemoteApp object.
  * @param      string $key (optional) key to use for instance map (for performance boost if key was already calculated externally).
  */
 public static function addInstanceToPool($obj, $key = null)
 {
     if (Propel::isInstancePoolingEnabled()) {
         if ($key === null) {
             $key = (string) $obj->getId();
         }
         // if key === null
         RemoteAppPeer::$instances[$key] = $obj;
     }
 }