protected function __getProjects($limit = null, $sort = 'title', $dir = 'asc') { $projects = Projects::get(); foreach ($projects as $id => $project) { $projects[$id] = $this->__initProjectInfo($id, $project); } uasort($projects, function ($a, $b) use($sort, $dir) { if ($dir == 'asc' && $a[$sort] < $b[$sort] || $dir == 'desc' && $a[$sort] > $b[$sort]) { return -1; } if ($dir == 'asc' && $a[$sort] > $b[$sort] || $dir == 'desc' && $a[$sort] < $b[$sort]) { return 1; } return 0; }); if (!empty($limit)) { $projects = array_slice($projects, 0, $limit); } return $projects; }
/** * @throws \Exception */ public function run() { if (!$this->command instanceof ProvisionCommand) { throw new \Exception("The ProjectsEnd task can only be run by the Provision command."); } $projects = Registry::get('projects', []); $hosts = Registry::get('projectsHosts', []); $shortcuts = Registry::get('projectsShortcuts', []); # Write projects catalog file $projects_catalog = array_merge($projects['skip'], $projects['check'], $projects['modify'], $projects['create']); if (Projects::writeCatalog($projects_catalog)) { $this->output->writeInfo("Updated projects catalog file"); } # Write hosts file so that it can be accessed later by the Hostmanager plugin if (Projects::writeHosts($hosts)) { $this->output->writeInfo("Updated projects hosts file"); } # Write shortcuts file so that it can be accessed later by dashbrew web dashboard if (Projects::writeShortcuts($shortcuts)) { $this->output->writeInfo("Updated projects shortcuts file"); } }
public static function getProjectCount() { return Projects::getCount(); }
/** * @throws \Exception */ public function run() { if (!$this->command instanceof ProvisionCommand) { throw new \Exception("The ProjectsInit task can only be run by the Provision command."); } $this->output->writeInfo("Finding projects"); $projects_catalog = Projects::get(); $projects = ['skip' => [], 'check' => [], 'modify' => [], 'create' => [], 'delete' => []]; $publicdb = '/etc/dashbrew/public.fndb'; $proc = Util::process($this->output, "updatedb -U /vagrant/public -o {$publicdb}"); if (!$proc->isSuccessful()) { throw new \Exception("Failed indexing '/vagrant/public' directory"); } $files = []; $proc = Util::process($this->output, "locate -d {$publicdb} -i -b '*.dashbrew'"); if ($proc->isSuccessful()) { $files = explode("\n", trim($proc->getOutput(), "\n")); } $yaml = Util::getYamlParser(); foreach ($files as $file_path) { if (!is_file($file_path)) { continue; } try { $file_projects = $yaml->parse(file_get_contents($file_path)); } catch (\Symfony\Component\Yaml\Exception\ParseException $e) { $this->output->writeError("Failed parsing '{$file_path}': " . $e->getMessage()); continue; } foreach ($file_projects as $id => $project) { $project['_path'] = $file_path; if (isset($projects_catalog[$id])) { $project['_created'] = $projects_catalog[$id]['_created']; $project['_modified'] = $projects_catalog[$id]['_modified']; if ($project == $projects_catalog[$id]) { if ($this->__projectNeedsCheck($id, $project)) { $projects['check'][$id] = $project; } else { $projects['skip'][$id] = $project; } } else { $project['_modified'] = time(); $projects['modify'][$id] = $project; } } else { # Ignore duplicates if (isset($projects['create'][$id])) { $this->output->writeError("Unable to proccess project '{$id}' at '{$project['_path']}', " . "another project with the same name is already exist at '{$projects['create'][$id]['_path']}'."); continue; } $project['_created'] = time(); $project['_modified'] = time(); $projects['create'][$id] = $project; } if (isset($projects_catalog[$id])) { unset($projects_catalog[$id]); } } } # Prevent project duplicates foreach ($projects['create'] as $id => $project) { foreach (['skip', 'check', 'modify'] as $action) { if (isset($projects[$action][$id])) { $this->output->writeError("Unable to proccess project '{$id}' at '{$project['_path']}', " . "another project with the same name is already exist at '{$projects[$action][$id]['_path']}'."); unset($projects['create'][$id]); } } } # Projects that are no longer exist needs to be deleted foreach ($projects_catalog as $id => $project) { $projects['delete'][$id] = $project; } Registry::set('projects', $projects); $projects_total = count($projects['skip']) + count($projects['check']) + count($projects['modify']) + count($projects['create']) + count($projects['delete']); if ($projects_total > count($projects['skip'])) { $this->output->writeInfo("Found " . $projects_total . " project(s)" . (count($projects['skip']) > 0 ? "\n |--> " . count($projects['skip']) . " will be skipped" : "") . (count($projects['check']) > 0 ? "\n |--> " . count($projects['check']) . " don't have changes but needs to be checked" : "") . (count($projects['create']) > 0 ? "\n |--> " . count($projects['create']) . " will be created" : "") . (count($projects['modify']) > 0 ? "\n |--> " . count($projects['modify']) . " will be modified" : "") . (count($projects['delete']) > 0 ? "\n |--> " . count($projects['delete']) . " will be deleted" : "")); } else { $this->output->writeDebug("Found {$projects_total} project(s)"); } }
/** * Renders actions output * * @param string|null $view * @throws \Exception */ protected function render($view = null) { if (empty($view) && !$this->rendered) { $view = $this->action; } $this->rendered = true; if (empty($view)) { $controller = get_class($this); throw new \Exception("Empty view path supplied to {$controller}::render"); } $view = 'controllers/' . $this->name . '/' . $view; $this->vars = array_merge($this->vars, ['app' => $this->app]); $output = $this->view->fetch($view, (array) $this->vars); $layout_vars = ['app' => $this->app, 'content' => $output]; if (!empty($this->vars['layout_title'])) { $layout_vars['layout_title'] = $this->vars['layout_title']; } else { $layout_vars['layout_title'] = Inflector::titleize($this->action); } $layout_vars['layout_breadcrumbs'] = ['app' => $this->app->getName(), 'controller' => Inflector::titleize($this->name)]; if ($this->action != 'index') { $layout_vars['layout_breadcrumbs']['action'] = $layout_vars['layout_title']; } $layout_vars['layout_shortcuts'] = Projects::getShortcuts(); if (!empty($this->vars['layout_breadcrumbs'])) { $layout_vars['layout_breadcrumbs'] = array_merge($layout_vars['layout_breadcrumbs'], (array) $this->vars['layout_breadcrumbs']); } $this->view->display('layouts/' . $this->layout, $layout_vars); }