8 * Repository ID (number in repositories directory)
15 * Full path to the .git repository
22 * Full path to the work tree directory
29 * Load Repository data from GET-Request
33 * @throws Exception When something is wrong
35 public function loadFromRequest()
37 if (!isset($_GET['id'])) {
38 throw new Exception_Input('Paste ID missing');
40 if (!is_numeric($_GET['id'])) {
41 throw new Exception_Input('Paste ID not numeric');
43 $this->id = (int)$_GET['id'];
47 protected function loadDirs()
49 $gitDir = $GLOBALS['phorkie']['cfg']['gitdir'] . '/' . $this->id . '.git';
50 if (!is_dir($gitDir)) {
51 throw new Exception_NotFound(
52 sprintf('Paste %d .git dir not found', $this->id)
55 $this->gitDir = $gitDir;
57 $workDir = $GLOBALS['phorkie']['cfg']['workdir'] . '/' . $this->id;
58 if (!is_dir($workDir)) {
59 throw new Exception_NotFound(
60 sprintf('Paste %d work dir not found', $this->id)
63 $this->workDir = $workDir;
66 public function loadById($id)
68 if (!is_numeric($id)) {
69 throw new Exception_Input('Paste ID not numeric');
75 public function getVc()
77 return new \VersionControl_Git($this->gitDir);
81 * Loads the list of files in this repository
83 * @return File[] Array of files
85 public function getFiles()
87 $files = glob($this->workDir . '/*');
89 foreach ($files as $path) {
90 $arFiles[] = new File($path, $this);
95 public function getFileByName($name, $bHasToExist = true)
97 $base = basename($name);
99 throw new Exception('No directories supported for now');
102 throw new Exception_Input('Empty file name given');
104 $path = $this->workDir . '/' . $base;
105 if ($bHasToExist && !is_readable($path)) {
106 throw new Exception_Input('File does not exist');
108 return new File($path, $this);
111 public function hasFile($name)
114 $this->getFileByName($name);
115 } catch (Exception $e) {
122 * Permanently deletes the paste repository without any way to get
125 * @return boolean True if all went well, false if not
127 public function delete()
129 return Tools::recursiveDelete($this->workDir)
130 && Tools::recursiveDelete($this->gitDir);
133 public function getDescription()
135 if (!is_readable($this->gitDir . '/description')) {
138 return file_get_contents($this->gitDir . '/description');
141 public function setDescription($description)
143 file_put_contents($this->gitDir . '/description', $description);
147 * Get a link to the repository
149 * @param string $type Link type. Supported are:
156 public function getLink($type)
158 if ($type == 'edit') {
159 return '/' . $this->id . '/edit';
160 } else if ($type == 'display') {
161 return '/' . $this->id;
162 } else if ($type == 'fork') {
163 return '/' . $this->id . '/fork';
164 } else if ($type == 'delete') {
165 return '/' . $this->id . '/delete';
166 } else if ($type == 'delete-confirm') {
167 return '/' . $this->id . '/delete/confirm';
169 throw new Exception('Unknown link type');
172 public function getCloneURL($public = true)
174 $var = $public ? 'public' : 'private';
175 if (isset($GLOBALS['phorkie']['cfg']['git'][$var])) {
176 return $GLOBALS['phorkie']['cfg']['git'][$var] . $this->id . '/.git';