/** * @return array */ public static function configure() { $io = PicCLI::getIO(); $io->outln("Please specify the full path to where the SQLite database file should be created."); $path = PicCLI::prompt("Path"); if (!$path) { $io->errln("No path specified."); exit(PicCLI::EXIT_INPUT); } if ($path[0] !== "/") { $io->errln("Must provide absolute path."); exit(PicCLI::EXIT_INPUT); } if (file_exists($path)) { $io->errln("Path to database file already exists."); exit(PicCLI::EXIT_INPUT); } if (!is_writeable(dirname($path))) { $io->errln("The current user does not have permission to write to that directory."); exit(PicCLI::EXIT_INPUT); } return array("path" => $path); }
$username = PicCLI::prompt("Username"); if (!$username) { $io->errln("No username specified."); exit(PicCLI::EXIT_INPUT); } } $id = loadPicFile("helpers/id/user.php", array("username" => $username)); if (!$id) { $io->errln(sprintf("User '%s' does not exist.", $username)); exit(PicCLI::EXIT_INPUT); } $idType = "users"; $label = $username; } elseif (PicCLI::getGetopt("--group")) { if (!($name = PicCLI::getGetopt(2))) { $name = PicCLI::prompt("Name"); if (!$name) { $io->errln("No group name specified."); exit(PicCLI::EXIT_INPUT); } } $id = loadPicFile("helpers/id/group.php", array("name" => $name)); if (!$id) { $io->errln(sprintf("Group '%s' does not exist.", $name)); exit(PicCLI::EXIT_INPUT); } $idType = "groups"; $label = $name; } else { $io->errln("No ID type specified."); exit(PicCLI::EXIT_USAGE);
$io->errln("No path ID specified."); exit(PicCLI::EXIT_USAGE); } if (!is_numeric($pathID)) { $io->errln("Invalid path ID specified."); exit(PicCLI::EXIT_INPUT); } $pathID = (int) $pathID; loadPicFile("classes/db.php"); PicDB::initDB(); if (!loadPicFile("helpers/id/path.php", array("id" => $pathID))) { $io->errln(sprintf("Path %d does not exist.", $pathID)); exit(PicCLI::EXIT_INPUT); } if (!($permission = PicCLI::getGetopt(2))) { $permission = PicCLI::prompt("Permission"); if (!$permission) { $io->errln("No permission specified."); exit(PicCLI::EXIT_INPUT); } } if (!in_array($permission, array("gps", "metadata", "nsfw", "symlinks"))) { $io->errln("Invalid permission supplied."); exit(PicCLI::EXIT_INPUT); } $select = PicDB::newSelect(); $select->cols(array("id"))->from("path_permissions")->where("path_id = :path_id")->where("permission = :permission")->bindValues(array("path_id" => $pathID, "permission" => $permission)); $row = PicDB::fetch($select, "one"); if ($row && $mode === "add") { PicCLI::warn(sprintf('Path \'%1$s\' already has the \'%2$s\' permission.', $pathID, $permission)); exit;
<?php PicCLI::initGetopt(array()); $io = PicCLI::getIO(); if (!($groupName = PicCLI::getGetopt(1))) { $groupName = PicCLI::prompt("Group"); if (!$groupName) { $io->errln("No group specified."); exit(PicCLI::EXIT_INPUT); } } if (!($username = PicCLI::getGetopt(2))) { $username = PicCLI::prompt("Username"); if (!$username) { $io->errln("No username specified."); exit(PicCLI::EXIT_INPUT); } } loadPicFile("classes/db.php"); PicDB::initDB(); $groupId = loadPicFile("helpers/id/group.php", array("name" => $groupName)); if (!$groupId) { $io->errln(sprintf("Group '%s' does not exist.", $groupName)); exit(PicCLI::EXIT_INPUT); } $userId = loadPicFile("helpers/id/user.php", array("username" => $username)); if (!$userId) { $io->errln(sprintf("User '%s' does not exist.", $username)); exit(PicCLI::EXIT_INPUT); } $select = PicDB::newSelect();
<?php PicCLI::initGetopt(array()); $io = PicCLI::getIO(); if (!($name = PicCLI::getGetopt(1))) { $name = PicCLI::prompt("Name"); if (!$name) { $io->errln("No name specified."); exit(PicCLI::EXIT_INPUT); } } if (!($username = PicCLI::getGetopt(2))) { $username = PicCLI::prompt("Username"); if (!$username) { $io->errln("No username specified."); exit(PicCLI::EXIT_INPUT); } } if (!($password = PicCLI::getGetopt(3))) { $password = PicCLI::prompt("Password"); if (!$password) { $io->errln("No password specified."); exit(PicCLI::EXIT_INPUT); } } loadPicFile("classes/db.php"); PicDB::initDB(); $insert = PicDB::newInsert(); $insert->into("users")->cols(array("name" => $name, "username" => $username, "password" => $password)); PicDB::crud($insert); PicCLI::success();
<?php PicCLI::initGetopt(array("sortorder:")); $io = PicCLI::getIO(); if (!($name = PicCLI::getGetopt(1))) { $name = PicCLI::prompt("Name"); if (!$name) { $io->errln("No name specified."); exit(PicCLI::EXIT_INPUT); } } if (!($path = PicCLI::getGetopt(2))) { $path = PicCLI::prompt("Path"); if (!$path) { $io->errln("No path specified."); exit(PicCLI::EXIT_INPUT); } } if ($path[0] !== "/") { $io->errln("Paths must be absolute, not relative."); exit(PicCLI::EXIT_INPUT); } $path = rtrim($path, "/") . "/"; loadPicFile("classes/db.php"); PicDB::initDB(); if ($sortOrder = PicCLI::getGetopt("--sortorder")) { $sortOrder = (int) $sortOrder; if ($sortOrder <= 0) { $io->errln("Sort orders must be above zero."); exit(PicCLI::EXIT_INPUT); }