6 public function __construct()
8 $this->workDir = $GLOBALS['phorkie']['cfg']['workdir'];
9 $this->gitDir = $GLOBALS['phorkie']['cfg']['gitdir'];
12 public function createNew(): Repository
15 $dirs = glob('*.git', GLOB_ONLYDIR);
16 foreach ($dirs as $key => $dir) {
17 $dirs[$key] = substr($dir, 0, -4);
19 sort($dirs, SORT_NUMERIC);
21 if ($GLOBALS['phorkie']['cfg']['randomIds']) {
22 $n = end($dirs) + mt_rand(65536, 16777216);
27 chdir($this->workDir);
28 $dir = $this->workDir . '/' . $n . '/';
29 mkdir($dir, fileperms($this->workDir) & 0777);
30 $r = new Repository();
33 $r->gitDir = $this->gitDir . '/' . $n . '.git/';
34 mkdir($r->gitDir, fileperms($this->gitDir) & 0777);
40 * Get a list of repository objects
42 * @param integer $page Page number, beginning with 0, or "last"
43 * @param integer $perPage Number of repositories per page
45 * @return array Array of Repositories first, number of repositories second
47 public function getList($page = 0, $perPage = 10): array
50 $dirs = glob('*.git', GLOB_ONLYDIR);
51 sort($dirs, SORT_NUMERIC);
52 if ($page === 'last') {
53 //always show the last 10
54 $page = intval(count($dirs) / $perPage);
55 $start = count($dirs) - $perPage;
59 $some = array_slice($dirs, $start, $perPage);
61 $some = array_slice($dirs, $page * $perPage, $perPage);
65 foreach ($some as $oneDir) {
66 $r = new Repository();
68 $r->loadById(substr($oneDir, 0, -4));
69 } catch (\VersionControl_Git_Exception $e) {
70 if (strpos($e->getMessage(), 'does not have any commits') !== false) {
71 //the git repo is broken as the initial commit
72 // has not been finished
79 return array($repos, count($dirs), $page);