解决成员删除回收站文件无权限问题

2024-07-17 23:52 更新
为了获取更多最新内容及功能更新,请直接访问我们的首页以查看DzzOffice笔记的最新地址。
文件地址:core\class\io\io_dzz.php
原代码
            //如果是文件夹
            if (!$filename) {
                $patharr = preg_split('/[\\\\\\/]/', $path);
                $patharr = array_filter($patharr);
                $filename = end($patharr);
            }

            if (!$icoarr = DB::fetch_first("select * from %t where pfid = %d and name = %s and isdelete < 1", array('resources', $pfid, $filename))) {
                return array('rid' => $icoarr['rid'], 'error' => lang('file_longer_exists'));
            }
            $size = 0;
            if ($icoarr['type'] == 'folder') {
                $contains = C::t('resources')->get_contains_by_fid($icoarr['oid'], true);
                $size = $contains['size'];
            } else {
                if ($icoarr['vid'] > 0) {
                    $size = DB::result_first("select sum(size) from %t where rid = %s", array('resources_version', $icoarr['rid']));
                } else {
                    $size = $icoarr['size'];
                }
            }
            if (perm_check::checkperm('delete', $icoarr)) {
                if ($force) {//强制彻底删除
                    C::t('resources')->delete_by_rid($path, true);
                } elseif ($icoarr['isdelete'] > 0) {//删除状态彻底删除
                    C::t('resources')->delete_by_rid($path, false);
                } else {//非删除状态删除到回收站
                    $return = C::t('resources')->recyle_by_rid($icoarr['rid']);
                    if ($return['error']) {
                        return $return;
                    }
                }
            } else {
                return array('rid' => $icoarr['rid'], 'error' => lang('no_privilege'));
            }
            if ($size > 0 && !$icoarr['isdelete']) {
                SpaceSize(-$size, $icoarr['gid'], true);
            }
            return array('rid' => $icoarr['rid'], 'name' => $icoarr['name']);
        } elseif (preg_match('/\w{32}/i', $path)) {//rid删除
            try {
                if (!$icoarr = C::t('resources')->fetch_info_by_rid($path)) {
                    return array('rid' => $path, 'error' => lang('file_longer_exists'));
                }
                $size = 0;
                if ($icoarr['type'] == 'folder') {
                    $contains = C::t('resources')->get_contains_by_fid($icoarr['oid'], true);
                    $size = $contains['size'];
                } else {
                    if ($icoarr['vid'] > 0) {
                        $size = DB::result_first("select sum(size) from %t where rid = %s", array('resources_version', $icoarr['rid']));
                    } else {
                        $size = $icoarr['size'];
                    }
                }
                if (perm_check::checkperm('delete', $icoarr)) {
                    if ($force) {//强制彻底删除
                        C::t('resources')->delete_by_rid($path, true);
                    } elseif ($icoarr['isdelete'] > 0) {//删除状态彻底删除
                        C::t('resources')->delete_by_rid($path, false);
                    } else {//非删除状态删除到回收站
                        $return = C::t('resources')->recyle_by_rid($icoarr['rid']);
                        if ($return['error']) {
                            return $return;
                        }
                    }
                } else {
                    return array('rid' => $icoarr['rid'], 'error' => lang('no_privilege'));
                }
                if ($size > 0 && !$icoarr['isdelete']) {
                    SpaceSize(-$size, $icoarr['gid'], true);
                }
                return array('rid' => $icoarr['rid'], 'name' => $icoarr['name']);
            } catch (Exception $e) {
                return array('error' => $e->getMessage());
            }
        }
    }

    //检查名称是否重复

修改后的代码

//如果是文件夹
            if (!$filename) {
                $patharr = preg_split('/[\\\\\\/]/', $path);
                $patharr = array_filter($patharr);
                $filename = end($patharr);
            }

            if ($rid = DB::result_first("select rid from %t where pfid = %d and name = %s and isdelete < 1", array('resources', $pfid, $filename))) {
                $icoarr=C::t('resources')->fetch_by_rid($rid);
            }else{
                 return array('rid' => $icoarr['rid'], 'error' => lang('file_longer_exists'));
            }

            if ($force || perm_check::checkperm('delete', $icoarr)) {
                if ($finaldelete) {//强制彻底删除
                    C::t('resources')->delete_by_rid($path, true);
                } elseif ($icoarr['isdelete'] > 0) {//删除状态彻底删除
                    C::t('resources')->delete_by_rid($path, true);
                } else {//非删除状态删除到回收站
                    $return = C::t('resources')->recyle_by_rid($icoarr['rid'],$force);
                    if ($return['error']) {
                        return $return;
                    }
                }
            } else {
                return array('rid' => $icoarr['rid'], 'error' => lang('no_privilege'));
            }
            
            return array('rid' => $icoarr['rid'], 'name' => $icoarr['name']);
        } elseif (preg_match('/\w{32}/i', $path)) {//rid删除
            try {
                if (!$icoarr = C::t('resources')->fetch_by_rid($path)) {
                    return array('rid' => $path, 'error' => lang('file_longer_exists'));
                }
                //当文件在回收站时,补全文件的原pfid(通过回收站表)
                if($icoarr['pfid']=='-1' && ($recycle=C::t('resources_recyle')->fetch_by_rid($path))){
                    $icoarr['pfid']=$recycle['pfid'];
                }
                //文件大小统计改到 resources表中处理
               /* $size = 0;
                if ($icoarr['type'] == 'folder') {
                    $contains = C::t('resources')->get_contains_by_fid($icoarr['oid'], true);
                    $size = $contains['size'];
                } else {
                    if ($icoarr['vid'] > 0) {
                        $size = DB::result_first("select sum(size) from %t where rid = %s", array('resources_version', $icoarr['rid']));
                    } else {
                        $size = $icoarr['size'];
                    }
                }*/
                if ($force || perm_check::checkperm('delete', $icoarr)) {
                    if ($finaldelete) {//强制彻底删除
                        C::t('resources')->delete_by_rid($path, true);
                    } elseif ($icoarr['isdelete'] > 0) {//删除状态彻底删除
                        C::t('resources')->delete_by_rid($path, true);
                    } else {//非删除状态删除到回收站
                        $return = C::t('resources')->recyle_by_rid($icoarr['rid'],$force);
                        if ($return['error']) {
                            return $return;
                        }
                    }
                } else {
                    return array('rid' => $icoarr['rid'], 'error' => lang('no_privilege'));
                }
                //文件大小统计改到 resources表中处理
                /*if ($size > 0 && !$icoarr['isdelete']) {
                    SpaceSize(-$size, $icoarr['gid'], true);
                }*/
                return array('rid' => $icoarr['rid'], 'name' => $icoarr['name']);
            } catch (Exception $e) {
                return array('error' => $e->getMessage());
            }
        }
    }

    //检查名称是否重复


以上内容是否对您有帮助:
在线笔记
App下载
App下载

扫描二维码

下载编程狮App

公众号
微信公众号

编程狮公众号