/** * @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"); } }
/** * Manages project shortcuts * * @param $action * @param $id * @param $project * @throws \Exception */ protected function processShortcuts($action, $id, $project) { $shortcuts = Registry::get('projectsShortcuts', []); foreach ($project['shortcuts'] as $shortcut) { if (!empty($shortcut['title']) && !empty($shortcut['url'])) { $shortcuts[] = $shortcut; } } Registry::set('projectsShortcuts', $shortcuts); }
/** * @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)"); } }