本文整理汇总了PHP中tao_helpers_File::deltree方法的典型用法代码示例。如果您正苦于以下问题:PHP tao_helpers_File::deltree方法的具体用法?PHP tao_helpers_File::deltree怎么用?PHP tao_helpers_File::deltree使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tao_helpers_File
的用法示例。
在下文中一共展示了tao_helpers_File::deltree方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __invoke
public function __invoke($params)
{
$parms = $params;
if (count($parms) < 1) {
echo 'Usage: ' . $script . ' IN_FILE [OUT_FILE]' . PHP_EOL;
die(1);
}
$package = array_shift($parms);
if (!file_exists($package)) {
echo 'Content package not found at "' . $package . '"' . PHP_EOL;
die(1);
}
if (!empty($parms)) {
$destination = array_shift($parms);
if (file_exists($destination)) {
echo 'File "' . $destination . '" already exists' . PHP_EOL;
die(1);
}
$this->dryRun = false;
} else {
$destination = null;
}
try {
// load extension
$directory = $this->extractPackage($package);
$this->addItems($directory);
while (!empty($this->todo)) {
$current = array_shift($this->todo);
$this->replaceXml($current);
}
if (!$this->dryRun) {
$this->recreatePackage($directory, $destination);
}
\tao_helpers_File::deltree($directory);
return new Report(Report::TYPE_SUCCESS);
} catch (UndefinedStrategy $exception) {
return new Report(Report::TYPE_ERROR, $exception->getMessage());
}
}
示例2: importMultipleTests
/**
* Import a QTI Test Package containing one or more QTI Test definitions.
*
* @param core_kernel_classes_Class $targetClass The Target RDFS class where you want the Test Resources to be created.
* @param string $file The path to the IMS archive you want to import tests from.
* @return common_report_Report An import report.
*/
public function importMultipleTests(core_kernel_classes_Class $targetClass, $file)
{
$testClass = $targetClass;
$report = new common_report_Report(common_report_Report::TYPE_INFO);
$validPackage = false;
$validManifest = false;
$testsFound = false;
// Validate the given IMS Package itself (ZIP integrity, presence of an 'imsmanifest.xml' file.
$invalidArchiveMsg = __("The provided archive is invalid. Make sure it is not corrupted and that it contains an 'imsmanifest.xml' file.");
try {
$qtiPackageParser = new taoQtiTest_models_classes_PackageParser($file);
$qtiPackageParser->validate();
$validPackage = true;
} catch (Exception $e) {
$report->add(common_report_Report::createFailure($invalidArchiveMsg));
}
// Validate the manifest (well formed XML, valid against the schema).
if ($validPackage === true) {
$folder = $qtiPackageParser->extract();
if (is_dir($folder) === false) {
$report->add(common_report_Report::createFailure($invalidArchiveMsg));
} else {
$qtiManifestParser = new taoQtiTest_models_classes_ManifestParser($folder . 'imsmanifest.xml');
$qtiManifestParser->validate();
if ($qtiManifestParser->isValid() === true) {
$validManifest = true;
$tests = array();
foreach (Resource::getTestTypes() as $type) {
$tests = array_merge($tests, $qtiManifestParser->getResources($type));
}
$testsFound = count($tests) !== 0;
if ($testsFound !== true) {
$report->add(common_report_Report::createFailure(__("Package is valid but no tests were found. Make sure that it contains valid QTI tests.")));
} else {
foreach ($tests as $qtiTestResource) {
$report->add($this->importTest($testClass, $qtiTestResource, $qtiManifestParser, $folder));
}
}
} else {
$msg = __("The 'imsmanifest.xml' file found in the archive is not valid.");
$report->add(common_report_Report::createFailure($msg));
}
// Cleanup the folder where the archive was extracted.
tao_helpers_File::deltree($folder);
}
}
if ($report->containsError() === true) {
$report->setMessage(__('The IMS QTI Test Package could not be imported.'));
$report->setType(common_report_Report::TYPE_ERROR);
} else {
$report->setMessage(__('IMS QTI Test Package successfully imported.'));
$report->setType(common_report_Report::TYPE_SUCCESS);
}
if ($report->containsError() === true && $validPackage === true && $validManifest === true && $testsFound === true) {
// We consider a test package as an atomic component, we then rollback it.
$itemService = taoItems_models_classes_ItemsService::singleton();
foreach ($report as $r) {
$data = $r->getData();
// Delete all imported items.
foreach ($data->items as $item) {
common_Logger::i("Rollbacking item '" . $item->getLabel() . "'...");
@$itemService->deleteItem($item);
}
// Delete the target Item RDFS class.
common_Logger::i("Rollbacking Items target RDFS class '" . $data->itemClass->getLabel() . "'...");
@$data->itemClass->delete();
// Delete test definition.
common_Logger::i("Rollbacking test '" . $data->rdfsResource->getLabel() . "...");
@$this->deleteTest($data->rdfsResource);
if (count($data->items) > 0) {
$msg = __("The resources related to the IMS QTI Test referenced as \"%s\" in the IMS Manifest file were rolled back.", $data->manifestResource->getIdentifier());
$report->add(new common_report_Report(common_report_Report::TYPE_WARNING, $msg));
}
}
}
return $report;
}