verifyParams($params); if ($report->getType() === \common_report_Report::TYPE_ERROR) { return $report; } $resourceDeleted = $this->class->countInstances([], ['recursive' => true]); if ($this->class->equals($this->service->getRootClass())) { foreach ($this->service->getRootClass()->getSubClasses() as $subClass) { if (!$this->service->deleteClass($subClass)) { return \common_report_Report::createFailure('Error occured during deletion of class : ' . $subClass->getUri()); } } $instances = $this->class->getInstances(); foreach ($instances as $instance) { if (!$this->service->deleteResource($instance)) { return \common_report_Report::createFailure('Error occured during deletion of resource : ' . $instance->getUri()); } } } else { if (!$this->service->deleteClass($this->class)) { return \common_report_Report::createFailure('Error occured during deletion of class : ' . $this->class->getUri()); } } $report->setMessage( 'All classes and instances under : ' . $this->class->getUri() . ' have been removed. ' . $resourceDeleted . ' resource(s) removed' ); return $report; } protected function verifyParams($params) { $this->finalReport = new \common_report_Report(\common_report_Report::TYPE_SUCCESS); if (isset($params[0])) { $serviceName = $params[0]; if (is_a($serviceName, OntologyClassService::class, true)) { $this->service = call_user_func([$serviceName, 'singleton'], []); } else { return new \common_report_Report(\common_report_Report::TYPE_ERROR, __('USAGE: please provide a valid service name as first parameter')); } } else { return new \common_report_Report(\common_report_Report::TYPE_ERROR, __('USAGE: please provide the service name as first parameter')); } if (isset($params[1])) { $extensionId = $params[1]; /** @var \common_ext_ExtensionsManager $extensionManager */ $extensionManager = $this->getServiceManager()->get(\common_ext_ExtensionsManager::SERVICE_ID); try { $extensionManager->getExtensionById($extensionId); } catch (ManifestNotFoundException $e) { return new \common_report_Report(\common_report_Report::TYPE_ERROR, __('USAGE: please provide a valid extension id as second parameter')); } } else { return new \common_report_Report(\common_report_Report::TYPE_ERROR, __('USAGE: please provide a valid extension id as second parameter')); } $class_uri = null; if (isset($params[2])) { $class_uri = $params[2]; } $rootClass = $this->service->getRootClass(); if (is_null($class_uri)) { $class = $rootClass; } else { $class = new \core_kernel_classes_Class($class_uri); if (!$class->isSubClassOf($rootClass)) { $msg = "Usage: php index.php '" . __CLASS__ . "' [CLASS_URI]" . PHP_EOL; $msg .= "CLASS_URI : a valid test class uri" . PHP_EOL . PHP_EOL; $msg .= "Uri : " . $class_uri . " is not a valid test class" . PHP_EOL; return \common_report_Report::createFailure($msg); } } $this->class = $class; return \common_report_Report::createSuccess('Valid parameters'); } }