Ejemplo n.º 1
0
 /**
  * @NoAdminRequired
  *
  * @param array $crop
  * @return DataResponse
  */
 public function postCroppedAvatar($crop)
 {
     $userId = $this->userSession->getUser()->getUID();
     if (is_null($crop)) {
         return new DataResponse(['data' => ['message' => $this->l->t("No crop data provided")]], Http::STATUS_BAD_REQUEST);
     }
     if (!isset($crop['x'], $crop['y'], $crop['w'], $crop['h'])) {
         return new DataResponse(['data' => ['message' => $this->l->t("No valid crop data provided")]], Http::STATUS_BAD_REQUEST);
     }
     $tmpAvatar = $this->cache->get('tmpAvatar');
     if (is_null($tmpAvatar)) {
         return new DataResponse(['data' => ['message' => $this->l->t("No temporary profile picture available, try again")]], Http::STATUS_BAD_REQUEST);
     }
     $image = new \OC_Image($tmpAvatar);
     $image->crop($crop['x'], $crop['y'], round($crop['w']), round($crop['h']));
     try {
         $avatar = $this->avatarManager->getAvatar($userId);
         $avatar->set($image);
         // Clean up
         $this->cache->remove('tmpAvatar');
         return new DataResponse(['status' => 'success']);
     } catch (\OC\NotSquareException $e) {
         return new DataResponse(['data' => ['message' => $this->l->t('Crop is not square')]], Http::STATUS_BAD_REQUEST);
     } catch (\Exception $e) {
         return new DataResponse(['data' => ['message' => $e->getMessage()]], Http::STATUS_BAD_REQUEST);
     }
 }
Ejemplo n.º 2
0
 /**
  * Delete a mailbox from the cache.
  *
  * @param string $mbox  The mailbox to delete.
  */
 protected function _deleteMailbox($mbox)
 {
     foreach (array_merge(array_keys(array_flip($this->_slicemap[$mbox]['s'])), array('slicemap')) as $slice) {
         $cid = $this->_getCid($mbox, $slice);
         $this->_cache->remove($cid);
         unset($this->_loaded[$cid]);
     }
     unset($this->_data[$mbox], $this->_slicemap[$mbox], $this->_update[$mbox]);
 }
Ejemplo n.º 3
0
 public function writeBack($tmpFile)
 {
     if (!isset(self::$tmpFiles[$tmpFile])) {
         return false;
     }
     $fileData = fopen($tmpFile, 'r');
     $this->getContainer()->uploadObject(self::$tmpFiles[$tmpFile], $fileData);
     // invalidate target object to force repopulation on fetch
     $this->objectCache->remove(self::$tmpFiles[$tmpFile]);
     unlink($tmpFile);
 }
Ejemplo n.º 4
0
 /**
  *
  * Clean previous results for a proper rescanning. Otherwise
  */
 private function cleanResults()
 {
     $this->config->deleteAppValue('core', self::CACHE_KEY);
     $this->cache->remove(self::CACHE_KEY);
 }
Ejemplo n.º 5
0
 /**
  * Remove a cached image by key.
  *
  * @param string $key
  */
 public function remove($key)
 {
     return $this->cache->remove($key);
 }