/** * @return PicCache */ private static function cacheInstance() { if (self::$cache === null) { self::$cache = new PicCache(); self::$cache->setPrefixSize(0); self::$cache->setDirectoryMode(0775); self::$cache->setCacheDirectory(CACHE_DIR . "/config"); } return self::$cache; }
$row = PicDB::fetch($select, "one"); class PicPathAccessException extends Exception { public $mode; public $idType; public $label; public static function initE($mode, $idType, $label) { $e = new self(); $e->mode = $mode; $e->idType = $idType; $e->label = $label; throw $e; } } if ($row && $mode === "add") { PicPathAccessException::initE($mode, $idType, $label); } elseif (!$row && $mode === "remove") { PicPathAccessException::initE($mode, $idType, $label); } if ($mode === "add") { $insert = PicDB::newInsert(); $insert->into("path_access")->cols(array("path_id" => $pathID, "auth_type" => $authType, "id_type" => $idType, "auth_id" => $id)); PicDB::crud($insert); } elseif ($mode === "remove") { $delete = PicDB::newDelete(); $delete->from("path_access")->where("id = :id")->bindValue("id", $row["id"]); PicDB::crud($delete); } PicConfCache::remove("pathauth.json"); PicCLI::success();
$authConfigTemplate = ["allow" => ["users" => [], "groups" => []], "deny" => ["users" => [], "groups" => []]]; $pathIDSelect = PicDB::newSelect(); $pathIDSelect->cols(array("id"))->from("paths"); $pathIDs = PicDB::fetch($pathIDSelect, "col"); $authConfig = array(); foreach ($pathIDs as $pathID) { $authConfig[$pathID] = $authConfigTemplate; } $accessSelect = PicDB::newSelect(); $accessSelect->cols(array("path_id", "id_type", "auth_id"))->from("path_access")->where("auth_type = :auth_type"); $accessSelect->bindValue("auth_type", "allow"); $allowRows = PicDB::fetch($accessSelect, "group", PDO::FETCH_NAMED); $accessSelect->bindValue("auth_type", "deny"); $denyRows = PicDB::fetch($accessSelect, "group", PDO::FETCH_NAMED); foreach ($allowRows as $path => $allowRow) { foreach ($allowRow as $auth) { $authConfig[$path]["allow"][$auth["id_type"]][] = $auth["auth_id"]; } } foreach ($denyRows as $path => $denyRow) { foreach ($denyRow as $auth) { $authConfig[$path]["deny"][$auth["id_type"]][] = $auth["auth_id"]; } } PicConfCache::set("pathauth.json", $authConfig); finalise: if (isset($selectedPathId)) { return $authConfig[$selectedPathId]; } else { return $authConfig; }