Ejemplo n.º 1
0
 public static function add($userID)
 {
     Z_Core::debug("Creating publications library for user {$userID}");
     Zotero_DB::beginTransaction();
     // Use same shard as user library
     $shardID = Zotero_Shards::getByUserID($userID);
     $libraryID = Zotero_Libraries::add('publications', $shardID);
     $sql = "INSERT INTO userPublications (userID, libraryID) VALUES (?, ?)";
     Zotero_DB::query($sql, [$userID, $libraryID]);
     Zotero_DB::commit();
     return $libraryID;
 }
Ejemplo n.º 2
0
 private static function getDeletedObjectIDs($userID, $timestamp, $includeAllUserObjects = false)
 {
     /*
     $sql = "SELECT version FROM version WHERE schema='syncdeletelog'";
     $syncLogStart = Zotero_DB::valueQuery($sql);
     if (!$syncLogStart) {
     	throw ('Sync log start time not found');
     }
     */
     /*
     // Last sync time is before start of log
     if ($lastSyncDate && new Date($syncLogStart * 1000) > $lastSyncDate) {
     	return -1;
     }
     */
     // Personal library
     $shardID = Zotero_Shards::getByUserID($userID);
     $libraryID = Zotero_Users::getLibraryIDFromUserID($userID);
     $shardLibraryIDs[$shardID] = array($libraryID);
     // Group libraries
     if ($includeAllUserObjects) {
         $groupIDs = Zotero_Groups::getUserGroups($userID);
         if ($groupIDs) {
             // Separate groups into shards for querying
             foreach ($groupIDs as $groupID) {
                 $libraryID = Zotero_Groups::getLibraryIDFromGroupID($groupID);
                 $shardID = Zotero_Shards::getByLibraryID($libraryID);
                 if (!isset($shardLibraryIDs[$shardID])) {
                     $shardLibraryIDs[$shardID] = array();
                 }
                 $shardLibraryIDs[$shardID][] = $libraryID;
             }
         }
     }
     // Send query at each shard
     $rows = array();
     foreach ($shardLibraryIDs as $shardID => $libraryIDs) {
         $sql = "SELECT libraryID, objectType, id, timestamp\n\t\t\t\t\tFROM syncDeleteLogIDs WHERE libraryID IN (" . implode(', ', array_fill(0, sizeOf($libraryIDs), '?')) . ")";
         $params = $libraryIDs;
         if ($timestamp) {
             // Send any entries from before these were being properly sent
             if ($timestamp < 1260778500) {
                 $sql .= " AND (timestamp >= FROM_UNIXTIME(?) OR timestamp BETWEEN 1257968068 AND FROM_UNIXTIME(?))";
                 $params[] = $timestamp;
                 $params[] = 1260778500;
             } else {
                 $sql .= " AND timestamp >= FROM_UNIXTIME(?)";
                 $params[] = $timestamp;
             }
         }
         $sql .= " ORDER BY timestamp";
         $shardRows = Zotero_DB::query($sql, $params, $shardID);
         if ($shardRows) {
             $rows = array_merge($rows, $shardRows);
         }
     }
     if (!$rows) {
         return false;
     }
     $deletedIDs = array('groups' => array());
     foreach ($rows as $row) {
         $type = $row['objectType'] . 's';
         $deletedIDs[$type][] = $row['id'];
     }
     return $deletedIDs;
 }
Ejemplo n.º 3
0
 /**
  * Used for integration tests
  *
  * Valid only on testing site
  */
 public function testSetup()
 {
     if (!$this->permissions->isSuper()) {
         $this->e404();
     }
     if (!Z_ENV_TESTING_SITE) {
         $this->e404();
     }
     $this->allowMethods(['POST']);
     if (empty($_GET['u'])) {
         throw new Exception("User not provided (e.g., ?u=1)");
     }
     $userID = $_GET['u'];
     // Clear keys
     $keys = Zotero_Keys::getUserKeys($userID);
     foreach ($keys as $keyObj) {
         $keyObj->erase();
     }
     $keys = Zotero_Keys::getUserKeys($userID);
     if ($keys) {
         throw new Exception("Keys still exist");
     }
     // Create new key
     $keyObj = new Zotero_Key();
     $keyObj->userID = $userID;
     $keyObj->name = "Tests Key";
     $libraryID = Zotero_Users::getLibraryIDFromUserID($userID);
     $keyObj->setPermission($libraryID, 'library', true);
     $keyObj->setPermission($libraryID, 'notes', true);
     $keyObj->setPermission($libraryID, 'write', true);
     $keyObj->setPermission(0, 'group', true);
     $keyObj->setPermission(0, 'write', true);
     $keyObj->save();
     $key = $keyObj->key;
     Zotero_DB::beginTransaction();
     // Clear data
     Zotero_Users::clearAllData($userID);
     // Delete publications library, so we can test auto-creating it
     $publicationsLibraryID = Zotero_Users::getLibraryIDFromUserID($userID, 'publications');
     if ($publicationsLibraryID) {
         // Delete user publications shard library
         $sql = "DELETE FROM shardLibraries WHERE libraryID=?";
         Zotero_DB::query($sql, $publicationsLibraryID, Zotero_Shards::getByUserID($userID));
         // Delete user publications library
         $sql = "DELETE FROM libraries WHERE libraryID=?";
         Zotero_DB::query($sql, $publicationsLibraryID);
         Z_Core::$MC->delete('userPublicationsLibraryID_' . $userID);
         Z_Core::$MC->delete('libraryUserID_' . $publicationsLibraryID);
     }
     Zotero_DB::commit();
     echo json_encode(["apiKey" => $key]);
     $this->end();
 }
Ejemplo n.º 4
0
 private function logGroupLibraryRemoval()
 {
     $users = $this->getUsers();
     $usersByShard = array();
     foreach ($users as $userID) {
         $shardID = Zotero_Shards::getByUserID($userID);
         if (!isset($usersByShard[$shardID])) {
             $usersByShard[$shardID] = array();
         }
         $usersByShard[$shardID][] = $userID;
     }
     foreach ($usersByShard as $shardID => $userIDs) {
         // Add to delete log for all group members
         $sql = "REPLACE INTO syncDeleteLogIDs (libraryID, objectType, id) VALUES ";
         $params = array();
         $sets = array();
         foreach ($userIDs as $userID) {
             $libraryID = Zotero_Users::getLibraryIDFromUserID($userID);
             $sets[] = "(?,?,?)";
             $params = array_merge($params, array($libraryID, 'group', $this->id));
         }
         $sql .= implode(",", $sets);
         Zotero_DB::query($sql, $params, $shardID);
     }
 }