Exemple #1
0
 /**
  * 
  * 创建file_meta的值
  * @param string $file_path
  * @param string $meta_key
  * @param string $meta_value
  * 
  * @since 1.0.7
  */
 public function createFileMeta($file_path, $meta_key, $meta_value)
 {
     $fileMeta = $this->find("file_path=:file_path and meta_key=:meta_key", array(":file_path" => $file_path, ":meta_key" => $meta_key));
     if (empty($fileMeta)) {
         $fileMeta = new FileMeta();
     }
     $fileMeta["file_path"] = $file_path;
     $fileMeta["meta_key"] = $meta_key;
     $fileMeta["meta_value"] = $meta_value;
     $fileMeta->save();
 }
Exemple #2
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;
 }
 /**
  * 清理file meta中多余的值
  * @param $limit
  */
 private function handleCleanFileMeta($limit)
 {
     $condition = 'meta_key="version" and file_path not in (';
     $condition .= 'select file_path from ';
     $condition .= UserFile::model()->tableName();
     $condition .= ' where file_type = 0 ';
     $condition .= ') limit ' . $limit;
     $fileMetas = FileMeta::model()->findAll($condition);
     foreach ($fileMetas as $fileMeta) {
         $metas = unserialize($fileMeta['meta_value']);
         $this->handleMeta($metas);
         $fileMeta->delete();
     }
 }
Exemple #4
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);
     }
 }
Exemple #5
0
 /**
  *
  * 发生重命名的时候,更新meta信息
  */
 private function handlerRenameShared()
 {
     $meta = FileMeta::model()->findByAttributes(array('file_path' => $this->_from, 'meta_key' => self::SHARED_META_FLAG));
     if (!$meta) {
         return false;
     }
     $meta_value = unserialize($meta['meta_value']);
     $updates = $meta_value['slaves'];
     //添加需要修改的权限用户的列表
     $this->modifyShareUsers = array_keys($updates);
     if ($meta_value['master'] == $this->_userId) {
         $meta_value['path'] = $this->_to;
         $updates[$this->_userId] = $this->_to;
     } else {
         $meta_value['slaves'][$this->_userId] = $this->_to;
         $updates[$meta_value['master']] = $meta_value['path'];
     }
     $meta_value['send_msg'] = $this->_send_msg;
     $meta_value = serialize($meta_value);
     FileMeta::model()->updateAll(array('meta_value' => $meta_value, 'file_path' => $this->_to), 'meta_key=:meta_key and file_path=:file_path', array(':meta_key' => self::SHARED_META_FLAG, ':file_path' => $this->_from));
     foreach ($updates as $v) {
         FileMeta::model()->updateAll(array('meta_value' => $meta_value), 'meta_key=:meta_key and file_path=:file_path', array(':meta_key' => self::SHARED_META_FLAG, ':file_path' => $v));
     }
     return true;
 }
Exemple #6
0
 /**
  * 根据from_path和meta_key=‘create_id’改file_path
  * @param $fromPath
  * @param $key
  * @param $toPath
  * @param $fileType
  * @return bool
  */
 public function modifyFilePath($fromPath, $key, $toPath, $fileType)
 {
     if ($fileType == 0) {
         //文件时候meta信息如下处理
         $criteria = new CDbCriteria();
         $criteria->condition = "meta_key=:meta_key and file_path=:file_path";
         $criteria->params = array("meta_key" => $key, "file_path" => $fromPath);
         $item = FileMeta::model()->find($criteria);
         if (!empty($item)) {
             $item->file_path = $toPath;
             $item->save();
         }
         return true;
     } else {
         //目录时meta信息如下处理
         $fromPathArr = explode('/', $fromPath);
         $toPathArr = explode('/', $toPath);
         $fromPathArrCount = count($fromPathArr);
         $toPathArrCount = count($toPathArr);
         $toFolderName = $toPathArr[$toPathArrCount - 1];
         $criteria = new CDbCriteria();
         $criteria->condition = "meta_key=:meta_key and file_path like :file_path";
         $criteria->params = array("meta_key" => $key, "file_path" => $fromPath . '%');
         $items = FileMeta::model()->findAll($criteria);
         foreach ($items as $item) {
             $itemPath = $item->file_path;
             $itemPathArr = explode('/', $itemPath);
             $itemPathArr[$fromPathArrCount - 1] = $toFolderName;
             $itemPathArrCount = count($itemPathArr);
             $newPath = "";
             for ($i = 1; $i < $itemPathArrCount; $i++) {
                 $newPath .= '/' . $itemPathArr[$i];
             }
             $item->file_path = $newPath;
             $item->save();
         }
         return true;
     }
 }
 /**
  * Adds an object to the instance pool.
  *
  * Propel keeps cached copies of objects in an instance pool when they are retrieved
  * from the database. In some cases you may need to explicitly add objects
  * to the cache in order to ensure that the same objects are always returned by find*()
  * and findPk*() calls.
  *
  * @param \FileMeta $obj A \FileMeta object.
  * @param string $key             (optional) key to use for instance map (for performance boost if key was already calculated externally).
  */
 public static function addInstanceToPool($obj, $key = null)
 {
     if (Propel::isInstancePoolingEnabled()) {
         if (null === $key) {
             $key = serialize([null === $obj->getUserAttributesIduserAttributes() || is_scalar($obj->getUserAttributesIduserAttributes()) || is_callable([$obj->getUserAttributesIduserAttributes(), '__toString']) ? (string) $obj->getUserAttributesIduserAttributes() : $obj->getUserAttributesIduserAttributes(), null === $obj->getMediafileIdmediafile() || is_scalar($obj->getMediafileIdmediafile()) || is_callable([$obj->getMediafileIdmediafile(), '__toString']) ? (string) $obj->getMediafileIdmediafile() : $obj->getMediafileIdmediafile()]);
         }
         // if key === null
         self::$instances[$key] = $obj;
     }
 }
Exemple #8
0
 /**
  *
  * 获得文件自身默认的权限
  *
  * @since 1.0.7
  */
 public function getFilePrivilege($file_path)
 {
     $meta = false;
     $count = substr_count($file_path, "/");
     while ($count > 1) {
         $meta = FileMeta::model()->find('file_path=:file_path and meta_key=:permission', array(':file_path' => $file_path, ':permission' => 'permission'));
         if (!empty($meta)) {
             break;
         } else {
             $fileInfo = pathinfo($file_path);
             $file_path = $fileInfo["dirname"];
             $count = substr_count($file_path, "/");
         }
     }
     if (!$meta) {
         return false;
     }
     return unserialize($meta->meta_value);
 }
Exemple #9
0
 /**
  * 
  * 创建meta信息
  */
 public function handleFileMeta($filePath, $versionId, $userId, $userNick, $action, $deviceName, $fileSize)
 {
     //
     // 查询之前的版本
     //
     $handler = new FileMeta();
     $meta = $handler->getFileMeta($filePath, "version");
     if ($meta) {
         $value = CUtils::getFileVersions($deviceName, $fileSize, $versionId, $action, $userId, $userNick, $meta["meta_value"]);
         $meta["meta_value"] = $value;
     } else {
         $meta = new FileMeta();
         $value = CUtils::getFileVersions($deviceName, $fileSize, $versionId, $action, $userId, $userNick);
         $meta["file_path"] = $filePath;
         $meta["meta_key"] = "version";
         $meta["meta_value"] = $value;
     }
     return $meta->save();
 }
Exemple #10
0
 /**
  * 根据path找到共享
  */
 public function handlerFindSlave($user_id, $path)
 {
     $meta = FileMeta::model()->findByAttributes(array('file_path' => $path, 'meta_key' => ShareManager::SHARED_META_FLAG));
     if (!$meta) {
         return false;
     }
     $meta_value = unserialize($meta['meta_value']);
     $slaves = $meta_value['slaves'];
     $slaves[$meta_value['master']] = $meta_value['path'];
     if (isset($slaves[$user_id])) {
         $file = UserFile::model()->findByAttributes(array('file_path' => $meta_value['path']));
         if ($file) {
             return $file['id'];
         }
     }
     return false;
 }
Exemple #11
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();
 }