Example #1
0
 /**
  * 历史版本恢复
  * @param int $deviceId
  * @param string $filePath
  * @param string $signature
  * @return bool
  */
 public function recover($deviceId, $filePath, $signature)
 {
     $version = MiniVersion::getInstance()->getBySignature($signature);
     $file = $this->getModelByPath($filePath);
     if ($version["id"] == $file['version_id']) {
         return true;
     }
     $device = MiniUserDevice::getInstance()->getById($deviceId);
     $userId = $device["user_id"];
     $user = MiniUser::getInstance()->getUser($userId);
     $userNick = $user["nick"];
     // events表 相关操作
     $userDeviceName = $device["user_device_name"];
     $userDeviceId = $device["id"];
     $signature = $version['file_signature'];
     $action = CConst::MODIFY_FILE;
     $file->file_update_time = time();
     $context = array('hash' => $signature, 'rev' => (int) $version["id"], 'bytes' => (int) $version['file_size'], 'update_time' => (int) $file->file_update_time, 'create_time' => (int) $file['file_create_time']);
     $filePath = $file['file_path'];
     $eventUuid = MiniUtil::getEventRandomString(CConst::LEN_EVENT_UUID);
     MiniEvent::getInstance()->createEvent($file['user_id'], $userDeviceId, $action, $filePath, serialize($context), $eventUuid);
     //create event
     // files表相关操作
     $file->version_id = $version["id"];
     $file->event_uuid = $eventUuid;
     $file->file_size = $version['file_size'];
     $file->save();
     // meta表相关操作
     $fileMeta = FileMeta::model()->find('file_path = ?', array($filePath));
     $versions = CUtils::getFileVersions($userDeviceName, $version['file_size'], $version["id"], CConst::WEB_RESTORE, $userId, $userNick, $fileMeta['meta_value']);
     $fileMeta->meta_value = $versions;
     $fileMeta->save();
     //更新版本引用数
     MiniVersion::getInstance()->updateRefCountByIds(array($version["id"]), TRUE);
     return true;
 }
Example #2
0
 /**
  * 
  * 更新文件meta信息,删除时添加版本
  * @param UserFile $file
  */
 public function handleFileMeta($filePath, $versionId, $userId, $userNick, $deviceName, $fileSize)
 {
     //
     // 查询之前的版本
     //
     $meta = new FileMeta();
     $meta = $meta->getFileMeta($filePath, "version");
     if ($meta) {
         $value = CUtils::getFileVersions($deviceName, $fileSize, $versionId, $this->_action, $userId, $userNick, $meta["meta_value"]);
         $meta["meta_value"] = $value;
     } else {
         $value = CUtils::getFileVersions($deviceName, $fileSize, $versionId, $this->_action, $userId, $userNick);
         $meta["file_path"] = $filePath;
         $meta["meta_key"] = "version";
         $meta["meta_value"] = $value;
     }
     return $meta->save();
 }
Example #3
0
 /**
  * 为更名文件创建meta版本
  */
 private function _saveFileMeta($filePath, $versionId, $userId, $userNick, $action, $deviceName, $fileSize)
 {
     //
     // 获取文件旧版本
     //
     $meta = FileMeta::model()->findByAttributes(array('file_path' => $filePath, 'meta_key' => 'version'));
     if (!$meta) {
         $meta = new FileMeta();
         $value = CUtils::getFileVersions($deviceName, $fileSize, $versionId, $action, $userId, $userNick);
         $meta["file_path"] = $filePath;
         $meta["meta_key"] = "version";
         $meta["meta_value"] = serialize(array());
     }
     $value = CUtils::getFileVersions($deviceName, $fileSize, $versionId, $action, $userId, $userNick, $meta["meta_value"]);
     $meta["meta_value"] = $value;
     $meta->save();
     if ($action == MConst::CREATE_FILE || $action == MConst::MODIFY_FILE || $action == CConst::WEB_RESTORE) {
         FileVersion::model()->updateRefCountByIds(array($versionId), TRUE);
     }
 }
Example #4
0
 /** 创建meta信息
  */
 public function handleFileMeta($filePath, $versionId, $userId, $userNick, $action, $deviceName, $fileSize)
 {
     //
     // 查询之前的版本
     //
     $handler = new FileMeta();
     $meta = $handler->getFileMeta($filePath, "version");
     if (!$meta) {
         $meta = new FileMeta();
         $meta["file_path"] = $filePath;
         $meta["meta_key"] = "version";
         $meta["meta_value"] = serialize(array());
     }
     $value = CUtils::getFileVersions($deviceName, $fileSize, $versionId, $action, $userId, $userNick, $meta["meta_value"]);
     $meta["meta_value"] = $value;
     if ($action == MConst::CREATE_FILE || $action == MConst::MODIFY_FILE || $action == CConst::WEB_RESTORE) {
         FileVersion::model()->updateRefCountByIds(array($versionId), TRUE);
     }
     return $meta->save();
 }