Exemplo n.º 1
0
 /**
  * Moves a file from one location to another
  *
  * @param string $sourcePath The path to the file which should be moved
  * @param string $destinationPath The full destination path, so not just the destination parent node
  * @return int
  */
 public function move($sourcePath, $destinationPath)
 {
     \GO::debug("ObjectTree::move({$sourcePath}, {$destinationPath})");
     $moveable = $this->getNodeForPath($sourcePath);
     $destination = $this->getNodeForPath(dirname($destinationPath));
     $targetServerPath = $destination->getServerPath() . '/' . \GO\Base\Fs\File::utf8Basename($destinationPath);
     $moveable->move($targetServerPath);
 }
Exemplo n.º 2
0
 protected function actionDownload($params)
 {
     \GO::session()->closeWriting();
     \GO::setMaxExecutionTime(0);
     if (isset($params['path'])) {
         $folder = \GO\Files\Model\Folder::model()->findByPath(dirname($params['path']));
         $file = $folder->hasFile(\GO\Base\Fs\File::utf8Basename($params['path']));
     } else {
         $file = \GO\Files\Model\File::model()->findByPk($params['id'], false, true);
     }
     if (!$file) {
         throw new \GO\Base\Exception\NotFound();
     }
     if (!empty($params['random_code'])) {
         if ($file->random_code != $params['random_code']) {
             throw new \GO\Base\Exception\NotFound();
         }
         if (time() > $file->expire_time) {
             throw new \Exception(\GO::t('downloadLinkExpired', 'files'));
         }
     } else {
         $public = substr($file->path, 0, 6) == 'public';
         if (!$public) {
             if (!\GO::user()) {
                 \GO\Base\Util\Http::basicAuth();
             }
             if (!$file->checkPermissionLevel(\GO\Base\Model\Acl::READ_PERMISSION)) {
                 throw new \GO\Base\Exception\AccessDenied();
             }
         }
     }
     // Show the file inside the browser or give it as a download
     $inline = true;
     // Defaults to show inside the browser
     if (isset($params['inline']) && $params['inline'] == "false") {
         $inline = false;
     }
     \GO\Base\Util\Http::outputDownloadHeaders($file->fsFile, $inline, !empty($params['cache']));
     $file->open();
     $this->fireEvent('beforedownload', array(&$this, &$params, &$file));
     $file->fsFile->output();
 }
Exemplo n.º 3
0
 public function getLastDownloadedFilename()
 {
     if (isset($this->lastHeaders['Content-Disposition']) && preg_match('/filename="(.*)"/', $this->lastHeaders['Content-Disposition'], $matches)) {
         return $matches[1];
     }
     $filename = \GO\Base\Fs\File::utf8Basename($this->_lastDownloadUrl);
     if (!empty($filename)) {
         return $filename;
     }
     return false;
 }
Exemplo n.º 4
0
 /**
  * Movesthe node
  *
  * @param string $name The new name
  * @return void
  */
 public function move($newPath)
 {
     $this->checkWritePermission();
     \GO::debug('DAVFile::move(' . $this->path . ' -> ' . $newPath . ')');
     $destFsFolder = new \GO\Base\Fs\Folder(dirname($newPath));
     $destFolder = \GO\Files\Model\Folder::model()->findByPath($destFsFolder->stripFileStoragePath());
     $file = \GO\Files\Model\File::model()->findByPath($this->relpath);
     $file->folder_id = $destFolder->id;
     $file->name = \GO\Base\Fs\File::utf8Basename($newPath);
     $file->save();
     $this->relpath = $file->path;
     $this->path = \GO::config()->file_storage_path . $this->relpath;
 }
Exemplo n.º 5
0
 /**
  * Find the file model by relative path.
  *
  * @param string $relpath Relative path from \GO::config()->file_storage_path
  * @return File
  */
 public function findByPath($relpath, $caseSensitive = true)
 {
     $folder = Folder::model()->findByPath(dirname($relpath), false, array(), $caseSensitive);
     if (!$folder) {
         return false;
     } else {
         return $folder->hasFile(\GO\Base\Fs\File::utf8Basename($relpath), $caseSensitive);
     }
 }
Exemplo n.º 6
0
 public function start(\GO\Base\Model\User $user = null, $reset = false)
 {
     if ($user === null) {
         $user = GO::user();
     }
     GO::session()->runAsRoot();
     GO::setMaxExecutionTime(0);
     self::log("Dropbox sync for user " . $user->username);
     $dbxUser = User::model()->findByPk($user->id);
     if ($reset) {
         $dbxUser->delta_cursor = "";
         $folder = self::getHomeFolder($user);
         $folder->removeChildren();
     }
     $dbxClient = self::getClient($user);
     self::log("Getting Dropbox Changes");
     $hasMore = true;
     while ($hasMore) {
         $delta = $dbxClient->Delta(empty($dbxUser->delta_cursor) ? null : $dbxUser->delta_cursor);
         //			var_dump($delta);
         //			exit();
         if (!isset($delta)) {
             throw new \Exception("Could not get delta from Dropbox!");
         }
         $hasMore = $delta->has_more;
         foreach ($delta->entries as $entry) {
             flush();
             //$entry[1]['path'] = with case. Otherwise we just have a string to lowered path for deleting
             $dbxPath = isset($entry[1]->path) ? $entry[1]->path : $entry[0];
             $goPath = self::dbxToGoPath($dbxPath, $user);
             if (!isset($entry[1])) {
                 //should be deleted
                 $file = File::model()->findByPath($goPath, false);
                 if ($file) {
                     self::log("Deleting file on Group-Office " . $goPath);
                     $file->delete();
                 } else {
                     $folder = Folder::model()->findByPath($goPath, false, array(), false);
                     if ($folder) {
                         self::log("Deleting folder on Group-Office " . $goPath);
                         $folder->delete();
                     } else {
                         self::log("Could not find path for delete file on Group-Office " . $goPath);
                     }
                 }
             } else {
                 if ($entry[1]->is_dir) {
                     self::log("Create folder on Group-Office " . $entry[1]->path . " -> " . $goPath);
                     $folder = Folder::model()->findByPath($goPath, true);
                 } else {
                     self::log("Download from Dropbox " . $entry[1]->path . " -> " . $goPath);
                     $folder = Folder::model()->findByPath(dirname($goPath), true, array(), false);
                     $name = \GO\Base\Fs\File::utf8Basename($goPath);
                     $path = $folder->fsFolder->createChild($name)->path();
                     //$f = fopen($path, "w+b");
                     $fileMetadata = $dbxClient->DownloadFile($entry[0], $path);
                     //fclose($f);
                     touch($path, strtotime($fileMetadata->modified));
                     //todo needs optimize
                     $folder->syncFilesystem();
                 }
             }
         }
     }
     $dbxUser->delta_cursor = $delta->cursor;
     $dbxUser->save();
     self::log("Applying Group-Office changes to Dropbox");
     $folder = self::getHomeFolder($user);
     $goSnapshot = self::getGroupOfficeSnapShot($folder);
     $dbxSnapshot = self::getDropboxSnapshot($user);
     foreach ($goSnapshot as $path => $props) {
         $dbxPath = self::goToDbxPath($props['path'], $user);
         $dbxPathToLower = strtolower($dbxPath);
         if (!isset($dbxSnapshot[$dbxPathToLower]) || $dbxSnapshot[$dbxPathToLower]['mtime'] < $props['mtime']) {
             if (is_file(GO::config()->file_storage_path . $props['path'])) {
                 self::log("Upload to Dropbox " . $path . " -> " . $dbxPath);
                 $localPath = GO::config()->file_storage_path . $props['path'];
                 $meta = $dbxClient->UploadFile($localPath, $dbxPath, true);
                 if (!isset($meta)) {
                     throw new \Exception("Failed to create file '" . $dbxPath . "' on Dropbox");
                 }
             } elseif (!isset($dbxSnapshot[$dbxPathToLower])) {
                 self::log("Create folder on Dropbox " . $path . " -> " . $dbxPath);
                 $folderMetaData = $dbxClient->CreateFolder($dbxPath);
                 if (!isset($folderMetaData)) {
                     throw new \Exception("Failed to create folder '" . $dbxPath . "' on Dropbox");
                 }
             }
         }
     }
     //reverse sort for deleting so that deeper files are deleted first.
     krsort($dbxSnapshot);
     foreach ($dbxSnapshot as $path => $props) {
         $goPath = strtolower(self::dbxToGoPath($path, $user));
         if (!isset($goSnapshot[$goPath])) {
             self::log("Deleting on dropbox " . $path);
             if (!$dbxClient->Delete($path)) {
                 throw new \Exception("Failed to delete '" . $path . "'");
             }
         }
     }
     //get delta again so we won't process our own changes next sync
     $delta = $dbxClient->Delta($dbxUser->delta_cursor);
     $dbxUser->delta_cursor = $delta->cursor;
     $dbxUser->save();
     self::log("Done!");
 }
Exemplo n.º 7
0
 public function __construct($filename, $config = array())
 {
     $this->_filename = \GO\Base\Fs\File::utf8Basename($filename);
     return parent::__construct($filename, $config);
 }