* @license PHP License * @package WB * @subpackage base */ WBClass::load( 'WBCli' ); /** * Command Line Interface class: VFS * * * @version 0.1.0 * @package WB * @subpackage base */ class WBCli_VFS extends WBCli { /** * Command line arguments * @var array */ protected $arguments = array( /* 'des' => array( 'short' => 'd', 'min' => 1, 'max' => 1, 'default' => '', 'desc' => 'Destination folder', ), 'user' => array( 'short' => 'u', 'min' => 1, 'max' => 1, 'default' => '', 'desc' => 'Owning user', ), */ 'older' => array( // 'short' => '', 'min' => 1, 'max' => 1, 'default' => '', 'desc' => 'Date, when files where deleted. Something like "1year" or "6month"', ), CONSOLE_GETARGS_PARAMS => array( 'min' => 1, 'max' => -1, 'default' => '', 'desc' => 'action and additional arguments', ) ); /** * VFS File * @var VFS_File */ private $file; /** * VFS Explorer * @var VFS_Explorer */ private $expl; /** * 2nd constructor * * @see include/WB/WBCli#init() */ protected function init() { } /** * execute programme * * Use observer and execute event queue */ protected function execute() { if (empty($this->commands)) { $this->pl('No command given.'); return 1; } $cmd = array_shift($this->commands); if (!method_exists($this, 'execute' . $cmd)) { $this->pl('Command ' . $cmd . ' not known.'); return 1; } return call_user_func(array($this, 'execute' . $cmd)); } private function executeFoo() { $this->pvl("foo"); $older = $this->args->getValue('older'); $this->pvl('older ' . $older); return 0; } private function executeFlush() { $older = $this->args->getValue('older'); if (empty($older)) { $this->pl('Cannot flush files. Older parameter is required.'); return 1; } $this->p('Flush '); $this->pvl('deleted files'); $older = '-' . $older; $this->pvl(sprintf(' older: %s', date('Y-m-d', strtotime($older)))); $this->startVFS($this->args->getValue('user')); $count = $this->file->flushDeleted($older); $this->pv(' count: '); $this->pl($count); return 0; } private function executeImport() { $this->pl('Not implemented, yet'); return 10; $user = $this->args->getValue('user'); if (empty($user)) { $this->pl('User id required'); return false; } $this->pvl('User: ' . $user); $des = $this->args->getValue('des'); $this->pvl('Destination: ' . $des); $this->startVFS4Import($user, $des); foreach ($this->commands as $file) { $name = basename($file); $this->file = $this->file->import($file, $name, true); $this->pl($this->file->getObscureId() . ' ' . $name); } return 0; } private function startVFS($user, $des = null) { $param = array(); if (!empty($user)) { $param['user'] = $user; } $this->file = WBClass::create('WBVFS_File', $param); $this->file->switchTranslation(false); if (!empty($des)) { $this->file->setCurrentDir($des); } } private function startVFS4Import($user, $des) { $param = array( 'user' => $user ); $this->file = WBClass::create('WBVFS_File', $param); $this->expl = WBClass::create('WBVFS_Explorer', $param); $this->file->switchTranslation(false); $this->expl->switchTranslation(false); if (!empty($des)) { $this->file->setCurrentDir($des); } } /** * get help text - head * * Override this method to set suitable help text * * @return string */ protected function getHelpHead() { $head = array(); $head[] = 'Newsletter Help'; $head[] = ''; $head[] = 'Usage: ' . basename($_SERVER['_']) . ' [OPTION]... COMMAND [ARGS...] '; $head[] = ''; $head[] = 'Commands: '; $head[] = ' - flush: remove deleted files until'; $head[] = ' - import: Import files for user in directory'; $head[] = 'Options:'; $head[] = ''; return implode("\n", $head); } }