/** * Returns the idArchive we will use for the current archive * * @return int IdArchive to use when saving the current Archive */ protected function loadNextIdarchive() { $table = $this->tableArchiveNumeric->getTableName(); $dbLockName = "loadNextIdArchive.{$table}"; $db = Zend_Registry::get('db'); $locked = self::PREFIX_SQL_LOCK . Piwik_Common::generateUniqId(); $date = date("Y-m-d H:i:s"); if (Piwik_GetDbLock($dbLockName, $maxRetries = 30) === false) { throw new Exception("loadNextIdArchive: Cannot get named lock for table {$table}."); } $db->exec("INSERT INTO {$table} " . " SELECT ifnull(max(idarchive),0)+1, \n\t\t\t\t\t\t\t\t'" . $locked . "',\n\t\t\t\t\t\t\t\t" . (int) $this->idsite . ",\n\t\t\t\t\t\t\t\t'" . $date . "',\n\t\t\t\t\t\t\t\t'" . $date . "',\n\t\t\t\t\t\t\t\t0,\n\t\t\t\t\t\t\t\t'" . $date . "',\n\t\t\t\t\t\t\t\t0 " . " FROM {$table} as tb1"); Piwik_ReleaseDbLock($dbLockName); $id = $db->fetchOne("SELECT idarchive FROM {$table} WHERE name = ? LIMIT 1", $locked); $this->idArchive = $id; }
/** * Release an advisory lock * * @param int $idsite * @param Piwik_Period $period * @param Piwik_Segment $segment * @return bool True if lock released; false otherwise */ public static function releaseArchiveProcessingLock($idsite, $period, $segment) { $lockName = self::getArchiveProcessingLockName($idsite, $period, $segment); return Piwik_ReleaseDbLock($lockName); }