public function writeSolrLog($entry)
 {
     KalturaLog::debug("writeSolrLog " . $entry->getId());
     $solrLog = new SphinxLog();
     $solrLog->setEntryId($entry->getId());
     $solrLog->setPartnerId($entry->getPartnerId());
     $solrLog->save(myDbHelper::getConnection(myDbHelper::DB_HELPER_CONN_SOLR_LOG));
 }
 /**
  * Performs the work of inserting or updating the row in the database.
  *
  * If the object is new, it inserts it; otherwise an update is performed.
  * All related objects are also updated in this method.
  *
  * @param      PropelPDO $con
  * @return     int The number of rows affected by this insert/update and any referring fk objects' save() operations.
  * @throws     PropelException
  * @see        save()
  */
 protected function doSave(PropelPDO $con)
 {
     $affectedRows = 0;
     // initialize var to track total num of affected rows
     if (!$this->alreadyInSave) {
         $this->alreadyInSave = true;
         // We call the save method on the following object(s) if they
         // were passed to this object by their coresponding set
         // method.  This object relates to these object(s) by a
         // foreign key reference.
         if ($this->aSphinxLog !== null) {
             if ($this->aSphinxLog->isModified() || $this->aSphinxLog->isNew()) {
                 $affectedRows += $this->aSphinxLog->save($con);
             }
             $this->setSphinxLog($this->aSphinxLog);
         }
         if ($this->isNew()) {
             $this->modifiedColumns[] = SphinxLogServerPeer::ID;
         }
         // If this object has been modified, then save it to the database.
         $this->objectSaved = false;
         if ($this->isModified()) {
             if ($this->isNew()) {
                 $pk = SphinxLogServerPeer::doInsert($this, $con);
                 $affectedRows += 1;
                 // we are assuming that there is only 1 row per doInsert() which
                 // should always be true here (even though technically
                 // BasePeer::doInsert() can insert multiple rows).
                 $this->setId($pk);
                 //[IMV] update autoincrement primary key
                 $this->setNew(false);
                 $this->objectSaved = true;
             } else {
                 $affectedObjects = SphinxLogServerPeer::doUpdate($this, $con);
                 if ($affectedObjects) {
                     $this->objectSaved = true;
                 }
                 $affectedRows += $affectedObjects;
             }
             $this->resetModified();
             // [HL] After being saved an object is no longer 'modified'
         }
         $this->alreadyInSave = false;
     }
     return $affectedRows;
 }
    if (is_null($entry)) {
        KalturaLog::err('Couldn\'t find entry [' . $entryId . ']');
        continue;
    }
    if ($entry->getViews() != $views || $entry->getPlays() != $plays) {
        $entry->setViews($views);
        $entry->setPlays($plays);
        KalturaLog::debug('Successfully saved entry [' . $entryId . ']');
        try {
            // update entry without setting the updated at
            $updateSql = "UPDATE entry set views='{$views}',plays='{$plays}' WHERE id='{$entryId}'";
            $stmt = $connection->prepare($updateSql);
            $stmt->execute();
            $affectedRows = $stmt->rowCount();
            KalturaLog::log("AffectedRows: " . $affectedRows);
            // update sphinx log directly
            $sql = $sphinxMgr->getSphinxSaveSql($entry, false);
            $sphinxLog = new SphinxLog();
            $sphinxLog->setEntryId($entryId);
            $sphinxLog->setPartnerId($entry->getPartnerId());
            $sphinxLog->setSql($sql);
            $sphinxLog->save(myDbHelper::getConnection(myDbHelper::DB_HELPER_CONN_SPHINX_LOG));
        } catch (Exception $e) {
            KalturaLog::log($e->getMessage(), Propel::LOG_ERR);
        }
    }
    $count++;
    if ($count % 500 === 0) {
        entryPeer::clearInstancePool();
    }
}
 /**
  * @param string $sql
  * @param IIndexable $object
  * @return bool
  */
 public function execSphinx($sql, IIndexable $object)
 {
     KalturaLog::debug($sql);
     $sphinxConnection = null;
     $sphinxConnectionId = null;
     if (kConf::hasParam('exec_sphinx') && kConf::get('exec_sphinx')) {
         $sphinxConnection = DbManager::getSphinxConnection(false);
         $sphinxServer = SphinxLogServerPeer::retrieveByLocalServer($sphinxConnection->getHostName());
         if ($sphinxServer) {
             $sphinxConnectionId = $sphinxServer->getId();
         }
     }
     $sphinxLog = new SphinxLog();
     $sphinxLog->setExecutedServerId($sphinxConnectionId);
     $sphinxLog->setObjectId($object->getId());
     $sphinxLog->setObjectType(get_class($object));
     $sphinxLog->setEntryId($object->getEntryId());
     $sphinxLog->setPartnerId($object->getPartnerId());
     $sphinxLog->setSql($sql);
     $sphinxLog->save(myDbHelper::getConnection(myDbHelper::DB_HELPER_CONN_SPHINX_LOG));
     if (!$sphinxConnection) {
         return true;
     }
     $sphinxConnection = DbManager::getSphinxConnection(false);
     $ret = $sphinxConnection->exec($sql);
     if ($ret) {
         return true;
     }
     $arr = $sphinxConnection->errorInfo();
     KalturaLog::err($arr[2]);
     return false;
 }
 /**
  * @param string $sql
  * @param IIndexable $object
  * @return bool
  */
 public function execSphinx($sql, IIndexable $object)
 {
     // limit the number of large sphinx SQLs to 1/min per object, since they load the sphinx database
     // and sphinx servers. the upper limit of 'slightly less than 1MB' is because of the max_allowed_packet
     // limit in mysql (by default 1MB). the upper limit is here to prevent the addition of too many category
     // users (for example), that will render the category un-indexable
     if (strlen($sql) > 128 * 1024 && strlen($sql) < 1000000) {
         $lockKey = 'large_sql_lock_' . get_class($object) . '_' . $object->getId();
         $cache = kCacheManager::getSingleLayerCache(kCacheManager::CACHE_TYPE_SPHINX_STICKY_SESSIONS);
         if ($cache && !$cache->add($lockKey, true, 60)) {
             KalturaLog::log('skipping sql for key ' . $lockKey);
             return;
         }
     }
     KalturaLog::debug($sql);
     $sphinxLog = new SphinxLog();
     $sphinxLog->setExecutedServerId($this->retrieveSphinxConnectionId());
     $sphinxLog->setObjectId($object->getId());
     $sphinxLog->setObjectType(get_class($object));
     $sphinxLog->setEntryId($object->getEntryId());
     $sphinxLog->setPartnerId($object->getPartnerId());
     $sphinxLog->setSql($sql);
     $sphinxLog->save(myDbHelper::getConnection(myDbHelper::DB_HELPER_CONN_SPHINX_LOG));
     if (!kConf::get('exec_sphinx', 'local', 0)) {
         return true;
     }
     $sphinxConnection = DbManager::getSphinxConnection(false);
     $ret = $sphinxConnection->exec($sql);
     if ($ret) {
         return true;
     }
     $arr = $sphinxConnection->errorInfo();
     KalturaLog::err($arr[2]);
     return false;
 }
 /**
  * @param string $sql
  * @param IIndexable $object
  * @return bool
  */
 public function execSphinx($sql, IIndexable $object)
 {
     KalturaLog::debug($sql);
     $sphinxLog = new SphinxLog();
     $sphinxLog->setEntryId($object->getEntryId());
     $sphinxLog->setPartnerId($object->getPartnerId());
     $sphinxLog->setSql($sql);
     $sphinxLog->save(myDbHelper::getConnection(myDbHelper::DB_HELPER_CONN_SPHINX_LOG));
     if (!kConf::hasParam('exec_sphinx') || !kConf::get('exec_sphinx')) {
         return true;
     }
     $con = DbManager::getSphinxConnection();
     $ret = $con->exec($sql);
     if ($ret) {
         return true;
     }
     $arr = $con->errorInfo();
     KalturaLog::err($arr[2]);
     return false;
 }