示例#1
0
 protected function processFromQueue()
 {
     return Zotero_Sync::checkUploadForErrors($this->id);
 }
示例#2
0
 public static function countUpdated($userID, $timestamp, $deletedCheckLimit = false)
 {
     $table = self::$table;
     $id = self::$idColumn;
     $type = self::$objectType;
     $types = self::$objectTypePlural;
     // First, see what libraries we actually need to check
     Zotero_DB::beginTransaction();
     // All libraries with update times >= $timestamp
     $updateTimes = Zotero_Libraries::getUserLibraryUpdateTimes($userID);
     $updatedLibraryIDs = array();
     foreach ($updateTimes as $libraryID => $lastUpdated) {
         if ($lastUpdated >= $timestamp) {
             $updatedLibraryIDs[] = $libraryID;
         }
     }
     $count = self::getUpdated($userID, $timestamp, $updatedLibraryIDs, true);
     // Make sure we really have fewer than 5
     if ($deletedCheckLimit < 5) {
         $count += Zotero_Sync::countDeletedObjectKeys($userID, $timestamp, $updatedLibraryIDs);
     }
     Zotero_DB::commit();
     return $count;
 }
示例#3
0
 function relaxNGErrorHandler($errno, $errstr)
 {
     Zotero_Sync::$validationError = $errstr;
 }
示例#4
0
 public function erase()
 {
     if (!$this->loaded) {
         Z_Core::debug("Not deleting unloaded group {$this->id}");
         return;
     }
     Zotero_DB::beginTransaction();
     $userIDs = self::getUsers();
     $this->logGroupLibraryRemoval();
     Zotero_Libraries::deleteCachedData($this->libraryID);
     Zotero_Libraries::clearAllData($this->libraryID);
     $sql = "DELETE FROM shardLibraries WHERE libraryID=?";
     $deleted = Zotero_DB::query($sql, $this->libraryID, Zotero_Shards::getByLibraryID($this->libraryID));
     if (!$deleted) {
         throw new Exception("Group not deleted");
     }
     $sql = "DELETE FROM libraries WHERE libraryID=?";
     $deleted = Zotero_DB::query($sql, $this->libraryID);
     if (!$deleted) {
         throw new Exception("Group not deleted");
     }
     // Delete key permissions for this library, and then delete any keys
     // that had no other permissions
     $sql = "SELECT keyID FROM keyPermissions WHERE libraryID=?";
     $keyIDs = Zotero_DB::columnQuery($sql, $this->libraryID);
     if ($keyIDs) {
         $sql = "DELETE FROM keyPermissions WHERE libraryID=?";
         Zotero_DB::query($sql, $this->libraryID);
         $sql = "DELETE K FROM `keys` K LEFT JOIN keyPermissions KP USING (keyID)\n\t\t\t\t\tWHERE keyID IN (" . implode(', ', array_fill(0, sizeOf($keyIDs), '?')) . ") AND KP.keyID IS NULL";
         Zotero_DB::query($sql, $keyIDs);
     }
     // If group is locked by a sync, flag group for a timestamp update
     // once the sync is done so that the uploading user gets the change
     try {
         foreach ($userIDs as $userID) {
             if ($syncUploadQueueID = Zotero_Sync::getUploadQueueIDByUserID($userID)) {
                 Zotero_Sync::postWriteLog($syncUploadQueueID, 'group', $this->id, 'delete');
             }
         }
     } catch (Exception $e) {
         Z_Core::logError($e);
     }
     Zotero_Notifier::trigger('delete', 'library', $this->libraryID);
     Zotero_DB::commit();
     $this->erased = true;
 }
示例#5
0
 private function handleUpdatedError(Exception $e)
 {
     if ($this->responseXML) {
         unset($this->responseXML->updated);
     } else {
         $this->responseXML = Zotero_Sync::getResponseXML($this->apiVersion);
     }
     $msg = $e->getMessage();
     //if (strpos($msg, "Can't connect to MySQL server on") !== false) {
     //	$this->error(503, 'SERVER_ERROR', "Syncing is currently unavailable for some users due to a server issue. We're working to restore service as soon as possible. Our apologies for the inconvenience.");
     //}
     if (strpos($msg, "Lock wait timeout exceeded; try restarting transaction") !== false || strpos($msg, "Deadlock found when trying to get lock; try restarting transaction") !== false || strpos($msg, "Too many connections") !== false || strpos($msg, "Can't connect to MySQL server") !== false || strpos($msg, " is down") !== false || $e->getCode() == Z_ERROR_SHARD_UNAVAILABLE) {
         $waitTime = $this->getWaitTime($this->sessionID);
         Z_Core::logError("WARNING: {$msg} -- sending sync wait ({$waitTime})");
         $locked = $this->responseXML->addChild('locked');
         $locked['wait'] = $waitTime;
         $this->end();
     }
     if (Z_ENV_TESTING_SITE) {
         throw $e;
     } else {
         $id = substr(md5(uniqid(rand(), true)), 0, 10);
         $str = date("D M j G:i:s T Y") . "\n";
         $str .= "IP address: " . $_SERVER['REMOTE_ADDR'] . "\n";
         if (isset($_SERVER['HTTP_X_ZOTERO_VERSION'])) {
             $str .= "Version: " . $_SERVER['HTTP_X_ZOTERO_VERSION'] . "\n";
         }
         $str .= "Error: " . $e;
         $str .= $this->responseXML->saveXML();
         if (!file_put_contents(Z_CONFIG::$SYNC_ERROR_PATH . $id, $str)) {
             error_log("Unable to save error report to " . Z_CONFIG::$SYNC_ERROR_PATH . $id);
         }
         $this->error(500, 'INVALID_OUTPUT', "Invalid response from server (Report ID: {$id})");
     }
 }
 protected function removeProcess($id)
 {
     Zotero_Sync::purgeErrorProcess($id);
 }
 public function clear()
 {
     $this->sessionCheck();
     if (Zotero_Sync::userIsReadLocked($this->userID) || Zotero_Sync::userIsWriteLocked($this->userID)) {
         $message = "You cannot reset server data while one of your libraries " . "is locked for syncing. Please wait for all related syncs to complete.";
         $this->error(400, 'SYNC_LOCKED', $message);
     }
     Zotero_Users::clearAllData($this->userID);
     $this->responseXML->addChild('cleared');
     $this->end();
 }