/** * Triggered by a `DELETE`, `COPY` or `MOVE`. The goal is to remove the * home directory of the principal. * * @param string $path Path. * @return bool */ function afterUnbind($path) { list($collection, $principalName) = SabreUri\split($path); if ('principals' !== $collection) { return false; } $out = true; $path = $this->storagePath . DS . $principalName; if (is_dir($path)) { $directory = new HoaFile\Directory($this->storagePath . DS . $principalName); $out = $directory->delete(); $directory->close(); } return $out; }
/** * The entry method. * * @return int */ public function main() { $libraries = []; while (false !== ($c = $this->getOption($v))) { switch ($c) { case 'a': $iterator = new File\Finder(); $iterator->in(resolve('hoa://Library/', true, true))->directories()->maxDepth(1); foreach ($iterator as $fileinfo) { $libraryName = $fileinfo->getBasename(); $pathname = resolve('hoa://Library/' . $libraryName); $automaticTests = $pathname . DS . 'Test' . DS . 'Praspel' . DS; if (is_dir($automaticTests)) { $libraries[] = $automaticTests; } } if (empty($libraries)) { echo 'Already clean.'; return; } break; case 'l': foreach ($this->parser->parseSpecialValue($v) as $library) { $libraryName = ucfirst(strtolower($library)); $pathname = resolve('hoa://Library/' . $libraryName); $automaticTests = $pathname . DS . 'Test' . DS . 'Praspel' . DS; if (is_dir($automaticTests)) { $libraries[] = $automaticTests; } } if (empty($libraries)) { echo 'Already clean.'; return; } break; case '__ambiguous': $this->resolveOptionAmbiguity($v); break; case 'h': case '?': default: return $this->usage(); } } if (empty($libraries)) { return $this->usage(); } foreach ($libraries as $path) { $status = 'Clean ' . (40 < strlen($path) ? '…' . substr($path, -39) : $path); echo ' ⌛ ', $status; $directory = new File\Directory($path); if (false === $directory->delete()) { echo ' ', Console\Chrome\Text::colorize('✖︎', 'foreground(red)'), ' ', $status, "\n"; } else { Console\Cursor::clear('↔'); echo ' ', Console\Chrome\Text::colorize('✔︎', 'foreground(green)'), ' ', $status, "\n"; } $directory->close(); } return; }