Exemple #1
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;
 }
Exemple #2
0
 /**
  * Used for integration tests
  *
  * Valid only on testing site
  */
 public function clear()
 {
     if (!$this->permissions->isSuper()) {
         $this->e404();
     }
     if (!Z_ENV_TESTING_SITE) {
         $this->e404();
     }
     $this->allowMethods(array('POST'));
     Zotero_Libraries::clearAllData($this->objectLibraryID);
     $this->e204();
 }
Exemple #3
0
 public static function clearAllData($userID)
 {
     if (empty($userID)) {
         throw new Exception("userID not provided");
     }
     Zotero_DB::beginTransaction();
     $libraryID = self::getLibraryIDFromUserID($userID, 'publications');
     if ($libraryID) {
         Zotero_Libraries::clearAllData($libraryID);
     }
     $libraryID = self::getLibraryIDFromUserID($userID);
     Zotero_Libraries::clearAllData($libraryID);
     // TODO: Better handling of locked out sessions elsewhere
     $sql = "UPDATE sessions SET timestamp='0000-00-00 00:00:00',\n\t\t\t\t\texclusive=0 WHERE userID=? AND exclusive=1";
     Zotero_DB::query($sql, $userID);
     Zotero_DB::commit();
 }