public function setMapPermission($mode = null)
    {
        $this->permissionError = array();
        $this->permissionErrorRules = array();

        $params = $this->getParams();

        $permissionRules = $this->permissionRules;
        if (isset($mode)) {
            foreach ($permissionRules as &$value) {
                $value = $mode;
            }
        }

        $result = true;
        foreach ($params['permissionMap'] as $type => $items) {

            $permission = $permissionRules[$type];

            foreach ($items as $item) {

                if (file_exists($item)) {

                    try {
                        $this->chmod($item, $permission, true);
                    } catch (\Exception $e) {
                    }

                    $res = is_readable($item);

                    /** check is wtitable */
                    if ($type == 'writable') {

                        $res &= is_writable($item);

                        if (is_dir($item)) {
                            $name = uniqid();

                            try {
                                $res &= $this->getFileManager()->putContents(array($item, $name), 'test');
                                $res &= $this->getFileManager()->removeFile($name, $item);
                            } catch (\Exception $e) {
                                $res = false;
                            }
                        }
                    }

                    if (!$res) {
                        $result = false;
                        $this->permissionError[] = $item;
                        $this->permissionErrorRules[$item] = $permission;
                    }
                }
            }
        }

        return $result;
    }