Esempio n. 1
0
 /**
  * Delete the storage with the given id.
  *
  * @param int $id storage id
  *
  * @throws NotFoundException if no storage was found with the given id
  */
 public function removeStorage($id)
 {
     $existingMount = $this->dbConfig->getMountById($id);
     if (!is_array($existingMount)) {
         throw new NotFoundException('Storage with id "' . $id . '" not found');
     }
     $this->dbConfig->removeMount($id);
     $deletedStorage = $this->getStorageConfigFromDBMount($existingMount);
     $this->triggerHooks($deletedStorage, Filesystem::signal_delete_mount);
     // delete oc_storages entries and oc_filecache
     try {
         $rustyStorageId = $this->getRustyStorageIdFromConfig($deletedStorage);
         \OC\Files\Cache\Storage::remove($rustyStorageId);
     } catch (\Exception $e) {
         // can happen either for invalid configs where the storage could not
         // be instantiated or whenever $user vars where used, in which case
         // the storage id could not be computed
         \OCP\Util::writeLog('files_external', 'Exception: "' . $e->getMessage() . '"', \OCP\Util::ERROR);
     }
 }
 /**
  * Fix the given legacy storage by renaming the old id
  * to the new id. If the new id already exists, whichever
  * storage that has data in the file cache will be used.
  * If both have data, nothing will be done and false is
  * returned.
  *
  * @param string $oldId old storage id
  * @param int $oldNumericId old storage numeric id
  * @param string $userId
  * @return bool true if fixed, false otherwise
  * @throws RepairException
  */
 private function fixLegacyStorage($oldId, $oldNumericId, $userId = null)
 {
     // check whether the new storage already exists
     if (is_null($userId)) {
         $userId = $this->extractUserId($oldId);
     }
     $newId = 'home::' . $userId;
     // check if target id already exists
     $newNumericId = Storage::getNumericStorageId($newId);
     if (!is_null($newNumericId)) {
         $newNumericId = (int) $newNumericId;
         // try and resolve the conflict
         // check which one of "local::" or "home::" needs to be kept
         $this->findStorageInCacheStatement->execute(array($oldNumericId, $newNumericId));
         $row1 = $this->findStorageInCacheStatement->fetch();
         $row2 = $this->findStorageInCacheStatement->fetch();
         $this->findStorageInCacheStatement->closeCursor();
         if ($row2 !== false) {
             // two results means both storages have data, not auto-fixable
             throw new RepairException('Could not automatically fix legacy storage ' . '"' . $oldId . '" => "' . $newId . '"' . ' because they both have data.');
         }
         if ($row1 === false || (int) $row1['storage'] === $oldNumericId) {
             // old storage has data, then delete the empty new id
             $toDelete = $newId;
         } else {
             if ((int) $row1['storage'] === $newNumericId) {
                 // new storage has data, then delete the empty old id
                 $toDelete = $oldId;
             } else {
                 // unknown case, do not continue
                 return false;
             }
         }
         // delete storage including file cache
         Storage::remove($toDelete);
         // if we deleted the old id, the new id will be used
         // automatically
         if ($toDelete === $oldId) {
             // nothing more to do
             return true;
         }
     }
     // rename old id to new id
     $newId = Storage::adjustStorageId($newId);
     $oldId = Storage::adjustStorageId($oldId);
     $rowCount = $this->renameStorageStatement->execute(array($newId, $oldId));
     $this->renameStorageStatement->closeCursor();
     return $rowCount === 1;
 }
Esempio n. 3
0
 /**
  * Updates old storage ids (v0.2.1 and older) that are based on key and secret to new ones based on the bucket name.
  * TODO Do this in an update.php. requires iterating over all users and loading the mount.json from their home
  *
  * @param array $params
  */
 public function updateLegacyId(array $params)
 {
     $oldId = 'amazon::' . $params['key'] . md5($params['secret']);
     // find by old id or bucket
     $stmt = \OC::$server->getDatabaseConnection()->prepare('SELECT `numeric_id`, `id` FROM `*PREFIX*storages` WHERE `id` IN (?, ?)');
     $stmt->execute(array($oldId, $this->id));
     while ($row = $stmt->fetch()) {
         $storages[$row['id']] = $row['numeric_id'];
     }
     if (isset($storages[$this->id]) && isset($storages[$oldId])) {
         // if both ids exist, delete the old storage and corresponding filecache entries
         \OC\Files\Cache\Storage::remove($oldId);
     } else {
         if (isset($storages[$oldId])) {
             // if only the old id exists do an update
             $stmt = \OC::$server->getDatabaseConnection()->prepare('UPDATE `*PREFIX*storages` SET `id` = ? WHERE `id` = ?');
             $stmt->execute(array($this->id, $oldId));
         }
     }
     // only the bucket based id may exist, do nothing
 }
Esempio n. 4
0
 /**
  * Delete the user
  *
  * @return bool
  */
 public function delete()
 {
     if ($this->emitter) {
         $this->emitter->emit('\\OC\\User', 'preDelete', array($this));
     }
     $result = $this->backend->deleteUser($this->uid);
     if ($result) {
         // FIXME: Feels like an hack - suggestions?
         // We have to delete the user from all groups
         foreach (\OC_Group::getUserGroups($this->uid) as $i) {
             \OC_Group::removeFromGroup($this->uid, $i);
         }
         // Delete the user's keys in preferences
         \OC::$server->getConfig()->deleteAllUserValues($this->uid);
         // Delete user files in /data/
         \OC_Helper::rmdirr(\OC_User::getHome($this->uid));
         // Delete the users entry in the storage table
         \OC\Files\Cache\Storage::remove('home::' . $this->uid);
         \OC::$server->getCommentsManager()->deleteReferencesOfActor('users', $this->uid);
         \OC::$server->getCommentsManager()->deleteReadMarksFromUser($this);
     }
     if ($this->emitter) {
         $this->emitter->emit('\\OC\\User', 'postDelete', array($this));
     }
     return !($result === false);
 }
Esempio n. 5
0
 /**
  * @brief delete a user
  * @param string $uid The username of the user to delete
  * @return bool
  *
  * Deletes a user
  */
 public static function deleteUser($uid)
 {
     $user = self::getManager()->get($uid);
     if ($user) {
         $result = $user->delete();
         // if delete was successful we clean-up the rest
         if ($result) {
             // We have to delete the user from all groups
             foreach (OC_Group::getUserGroups($uid) as $i) {
                 OC_Group::removeFromGroup($uid, $i);
             }
             // Delete the user's keys in preferences
             OC_Preferences::deleteUser($uid);
             // Delete user files in /data/
             $home = \OC_User::getHome($uid);
             OC_Helper::rmdirr($home);
             // Delete the users entry in the storage table
             \OC\Files\Cache\Storage::remove('home::' . $uid);
             \OC\Files\Cache\Storage::remove('local::' . $home . '/');
             // Remove it from the Cache
             self::getManager()->delete($uid);
         }
         return true;
     } else {
         return false;
     }
 }