] [-h] [-v] -f -e -d ".PHP_EOL; echo PHP_EOL; echo "Description:".PHP_EOL; echo " This program deletes a folder or document.".PHP_EOL; echo PHP_EOL; echo "Options:".PHP_EOL; echo " -h, --help: print usage information and exit.".PHP_EOL; echo " -v, --version: print version and exit.".PHP_EOL; echo " --config: set alternative config file.".PHP_EOL; echo " -f : id of folder to be deleted".PHP_EOL; echo " -e : id of folder to be emptied".PHP_EOL; echo " -d : id of document to be deleted".PHP_EOL; echo " -u : login name of user".PHP_EOL; echo PHP_EOL; echo "If the user is not given the user with id 1 will be used.".PHP_EOL; echo "The options -d, -e and -f can be passed multiple times or the option value".PHP_EOL; echo "can be a comma separated list of ids.".PHP_EOL; } /* }}} */ $version = "0.0.1"; $shortoptions = "e:f:d:u:hv"; $longoptions = array('help', 'version', 'config:'); if(false === ($options = getopt($shortoptions, $longoptions))) { usage(); exit(0); } /* Print help and exit */ if(isset($options['h']) || isset($options['help'])) { usage(); exit(0); } /* Print version and exit */ if(isset($options['v']) || isset($options['verŅ•ion'])) { echo $version.PHP_EOL; exit(0); } /* Set alternative config file */ if(isset($options['config'])) { define('SEEDDMS_CONFIG_FILE', $options['config']); } elseif(isset($_SERVER['SEEDDMS_CONFIG_FILE'])) { define('SEEDDMS_CONFIG_FILE', $_SERVER['SEEDDMS_CONFIG_FILE']); } /* Set folders to be deleted */ $folderids = array(); if(isset($options['f'])) { if(is_string($options['f'])) $folderids = explode(',', $options['f']); else $folderids = $options['f']; } /* Set folders to be emptied */ $emptyids = array(); if(isset($options['e'])) { if(is_string($options['e'])) $emptyids = explode(',', $options['e']); else $emptyids = $options['e']; } /* Set documents to be deleted */ $documentids = array(); if(isset($options['d'])) { if(is_string($options['d'])) $documentids = explode(',', $options['d']); else $documentids = $options['d']; } if(!$documentids && !$folderids && !$emptyids) { echo "Neither folder ids nor document ids were given".PHP_EOL; usage(); exit(1); } $username = ''; if(isset($options['u'])) { $username = $options['u']; } include($myincpath."/inc/inc.Settings.php"); include($myincpath."/inc/inc.Init.php"); include($myincpath."/inc/inc.Extension.php"); include($myincpath."/inc/inc.DBInit.php"); include($myincpath."/inc/inc.ClassNotificationService.php"); include($myincpath."/inc/inc.Notification.php"); include($myincpath."/inc/inc.ClassController.php"); /* Create a global user object {{{ */ if($username) { if(!($user = $dms->getUserByLogin($username))) { echo "No such user '".$username."'."; exit; } } else $user = $dms->getUser(1); $dms->setUser($user); /* }}} */ foreach($folderids as $folderid) { $folder = $dms->getFolder($folderid); if (!is_object($folder)) { echo "Could not find folder with id ".$folderid.PHP_EOL; } else { if ($folder->getAccessMode($user) < M_READWRITE) { echo "Not sufficient access rights on folder with id ".$folderid.PHP_EOL; } else { $controller = Controller::factory('RemoveFolder', array('dms'=>$dms, 'user'=>$user)); $controller->setParam('folder', $folder); $controller->setParam('fulltextservice', $fulltextservice); if(!$document = $controller->run()) { echo "Could not remove folder with id ".$folderid.PHP_EOL; } else { echo "Folder with id ".$folderid." removed.".PHP_EOL; } } } } foreach($emptyids as $folderid) { $folder = $dms->getFolder($folderid); if (!is_object($folder)) { echo "Could not find folder with id ".$folderid.PHP_EOL; } if ($folder->getAccessMode($user) < M_READWRITE) { echo "Not sufficient access rights on folder with id ".$folderid.PHP_EOL; } $controller = Controller::factory('EmptyFolder', array('dms'=>$dms, 'user'=>$user)); $controller->setParam('folder', $folder); $controller->setParam('fulltextservice', $fulltextservice); if(!$document = $controller->run()) { echo "Could not empty folder with id ".$folderid.PHP_EOL; } else { echo "Folder with id ".$folderid." emptied.".PHP_EOL; } } foreach($documentids as $documentid) { $document = $dms->getDocument($documentid); if (!is_object($document)) { echo "Could not find specified document with id ".$documentid.PHP_EOL; } if ($document->getAccessMode($user) < M_READWRITE) { echo "Not sufficient access rights on document with id ".$documentid.PHP_EOL; } $controller = Controller::factory('RemoveDocument', array('dms'=>$dms, 'user'=>$user)); $controller->setParam('document', $document); $controller->setParam('fulltextservice', $fulltextservice); if(!$document = $controller->run()) { echo "Could not remove document with id ".$documentid.PHP_EOL; } else { echo "Document with id ".$documentid." removed.".PHP_EOL; } }