/** * * 创建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(); }
/** * 为更名文件创建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); } }
/** * * 为已经共享的文件夹添加用户 * * @since 1.0.7 */ private function handlerAddUser2Shared() { // // 检查是否是共享目录 // $this->handlerCheck(2); if (empty($this->_slaves) || $this->_slaves == '-1') { throw new ApiException("参数错误"); } // // 将逗号分割的id组装成数组 // $this->_slaves = array_slice(explode(',', $this->_slaves), 0); $this->_types = array_slice(explode(',', $this->_types), 0); $this->_master = $this->_userId; $file_meta = FileMeta::model()->findByAttributes(array('file_path' => $this->_file['file_path'], 'meta_key' => self::SHARED_META_FLAG)); if (empty($file_meta)) { throw new ApiException('Not Found'); } $meta_value = unserialize($file_meta['meta_value']); if ($this->_master != $meta_value['master']) { throw new ApiException('Forbidden'); } $slaves = $meta_value['slaves']; // // 为新的用户创建文件夹 // $metas = $this->handlerCreateFolder($slaves); // 一个用户都没添加 if (count($metas) == 0 && $this->_send_msg == $meta_value['send_msg']) { return true; } $meta_value['slaves'] = $slaves + $metas; $meta_value['send_msg'] = $this->_send_msg; $meta_value = serialize($meta_value); $slaves[$this->_master] = $this->_file['file_path']; // // 更新老数据 // foreach ($slaves as $k => $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)); } // // 创建新数据 // foreach ($metas as $k => $v) { $meta = new FileMeta(); $meta['meta_value'] = $meta_value; $meta['file_path'] = $v; $meta['meta_key'] = self::SHARED_META_FLAG; $meta->save(); } }
/** * 设置公共目录权限 * @param $filePath 文件路径 * @param $privilege 权限 * @return array */ public function setPublicPrivilege($filePath, $privilege) { $meta_key = MConst::PUBLIC_FOLDER; $fileMeta = $this->getModelByPath($filePath, $meta_key); if (empty($fileMeta)) { $fileMeta = new FileMeta(); } $fileMeta["file_path"] = $filePath; $fileMeta["meta_key"] = $meta_key; $fileMeta["meta_value"] = $privilege; $fileMeta->save(); return array('success' => true); }
/** * * 创建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(); }
/** 创建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(); }