-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #188 from oat-sa/release-2.20.0
Release 2.20.0
- Loading branch information
Showing
17 changed files
with
815 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
<?php | ||
/** | ||
* This program is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU General Public License | ||
* as published by the Free Software Foundation; under version 2 | ||
* of the License (non-upgradable). | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program; if not, write to the Free Software | ||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
* | ||
* Copyright (c) 2015 (original work) Open Assessment Technologies SA (under the project TAO-PRODUCT); | ||
* | ||
*/ | ||
namespace oat\oatbox\action; | ||
|
||
use oat\oatbox\service\ConfigurableService; | ||
use oat\oatbox\service\ServiceNotFoundException; | ||
use Zend\ServiceManager\ServiceLocatorAwareInterface; | ||
|
||
class ActionService extends ConfigurableService | ||
{ | ||
const SERVICE_ID = 'generis/actionService'; | ||
|
||
static $blackList = array('\\oatbox\\composer\\ExtensionInstaller','\\oatbox\\composer\\ExtensionInstallerPlugin'); | ||
|
||
/** | ||
* | ||
* @param string $actionIdentifier | ||
* @return Action | ||
*/ | ||
public function resolve($actionIdentifier) | ||
{ | ||
$action = null; | ||
if ($this->getServiceLocator()->has($actionIdentifier)) { | ||
$action = $this->getServiceManager()->get($actionIdentifier); | ||
} elseif (class_exists($actionIdentifier) && is_subclass_of($actionIdentifier, Action::class)) { | ||
$action = new $actionIdentifier(); | ||
if ($action instanceof ServiceLocatorAwareInterface) { | ||
$action->setServiceLocator($this->getServiceLocator()); | ||
} | ||
} else { | ||
throw new ResolutionException('Unknown action '.$actionIdentifier); | ||
} | ||
return $action; | ||
} | ||
|
||
public function getAvailableActions() | ||
{ | ||
if ($this->getCache()->has(__FUNCTION__)) { | ||
$actions = $this->getCache()->get(__FUNCTION__); | ||
} else { | ||
$actions = array(); | ||
foreach (\common_ext_ExtensionsManager::singleton()->getInstalledExtensions() as $ext) { | ||
$actions = array_merge($actions, $this->getActionsInDirectory($ext->getDir())); | ||
} | ||
$actions = array_merge($actions, $this->getActionsInDirectory(VENDOR_PATH.'oat-sa')); | ||
$this->getCache()->put($actions, __FUNCTION__); | ||
} | ||
return $actions; | ||
} | ||
|
||
/** | ||
* @return \common_cache_Cache | ||
*/ | ||
protected function getCache() | ||
{ | ||
return $this->getServiceManager()->get('generis/cache'); | ||
} | ||
|
||
protected function getActionsInDirectory($dir) | ||
{ | ||
$classNames = array(); | ||
$recIt = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($dir)); | ||
$regexIt = new \RegexIterator($recIt, '/^.+\.php$/i', \RecursiveRegexIterator::GET_MATCH); | ||
foreach ($regexIt as $entry) { | ||
$info = \helpers_PhpTools::getClassInfo($entry[0]); | ||
$fullname = empty($info['ns']) | ||
? $info['class'] | ||
: $info['ns'].'\\'.$info['class']; | ||
if (!in_array($fullname, self::$blackList) && is_subclass_of($fullname, Action::class)) { | ||
$classNames[] = $fullname; | ||
} | ||
} | ||
return $classNames; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?php | ||
/** | ||
* This program is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU General Public License | ||
* as published by the Free Software Foundation; under version 2 | ||
* of the License (non-upgradable). | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program; if not, write to the Free Software | ||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
* | ||
* Copyright (c) 2015 (original work) Open Assessment Technologies SA (under the project TAO-PRODUCT); | ||
* | ||
*/ | ||
namespace oat\oatbox\action; | ||
|
||
|
||
use oat\oatbox\service\ServiceNotFoundException; | ||
use Zend\ServiceManager\ServiceLocatorAwareTrait; | ||
use Zend\ServiceManager\ServiceLocatorAwareInterface; | ||
|
||
class Help implements Action, ServiceLocatorAwareInterface | ||
{ | ||
use ServiceLocatorAwareTrait; | ||
|
||
public function __invoke($params) { | ||
$actionResolver = $this->getServiceLocator()->get(ActionService::SERVICE_ID); | ||
$report = new \common_report_Report(\common_report_Report::TYPE_INFO, __('Available Actions:')); | ||
foreach ($actionResolver->getAvailableActions() as $actionClass) { | ||
$report->add(new \common_report_Report(\common_report_Report::TYPE_INFO, ' '.$actionClass)); | ||
} | ||
return $report; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php | ||
/** | ||
* This program is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU General Public License | ||
* as published by the Free Software Foundation; under version 2 | ||
* of the License (non-upgradable). | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program; if not, write to the Free Software | ||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
* | ||
* Copyright (c) 2014 (original work) Open Assessment Technologies SA; | ||
* | ||
* | ||
*/ | ||
namespace oat\oatbox\task; | ||
|
||
use oat\oatbox\service\ConfigurableService; | ||
use oat\Taskqueue\Persistence\RdsQueue; | ||
use Doctrine\DBAL\Schema\SchemaException; | ||
use oat\oatbox\service\ServiceManager; | ||
use oat\oatbox\task\Queue; | ||
use oat\oatbox\action\Action; | ||
use oat\oatbox\task\TaskRunner; | ||
use common_report_Report as Report; | ||
|
||
class RunTasks extends ConfigurableService implements Action | ||
{ | ||
public function __invoke($params) { | ||
$taskService = new TaskService(); | ||
$taskService->setServiceLocator($this->getServiceLocator()); | ||
$report = $taskService->runQueue(); | ||
return $report; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
<?php | ||
/** | ||
* This program is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU General Public License | ||
* as published by the Free Software Foundation; under version 2 | ||
* of the License (non-upgradable). | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program; if not, write to the Free Software | ||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
* | ||
* Copyright (c) 2014 (original work) Open Assessment Technologies SA; | ||
* | ||
* | ||
*/ | ||
namespace oat\oatbox\task; | ||
|
||
use oat\oatbox\service\ConfigurableService; | ||
use common_report_Report as Report; | ||
|
||
class TaskService extends ConfigurableService | ||
{ | ||
/** | ||
* @var TaskRunner | ||
*/ | ||
private $taskRunner; | ||
|
||
/** | ||
* @param Task $task | ||
* @return Report | ||
*/ | ||
public function runTask(Task $task) | ||
{ | ||
$taskRunner = $this->getTaskRunner(); | ||
return $taskRunner->run($task); | ||
} | ||
|
||
/** | ||
* @return Report | ||
* @throws \common_exception_Error | ||
*/ | ||
public function runQueue() | ||
{ | ||
$statistics = array(); | ||
$queue = $this->getServiceManager()->get(Queue::CONFIG_ID); | ||
$report = new Report(Report::TYPE_SUCCESS); | ||
foreach ($queue as $task) { | ||
$subReport = $this->runTask($task); | ||
$statistics[$subReport->getType()] = isset($statistics[$subReport->getType()]) | ||
? $statistics[$subReport->getType()] + 1 | ||
: 1; | ||
$report->add($subReport); | ||
} | ||
|
||
if (empty($statistics)) { | ||
$report = new Report(Report::TYPE_INFO, __('No tasks to run')); | ||
} else { | ||
if (isset($statistics[Report::TYPE_ERROR]) || isset($statistics[Report::TYPE_WARNING])) { | ||
$report->setType(Report::TYPE_WARNING); | ||
} | ||
$report->setMessage(__('Ran %s task(s):', array_sum($statistics))); | ||
} | ||
return $report; | ||
} | ||
|
||
/** | ||
* @return TaskRunner | ||
*/ | ||
private function getTaskRunner() | ||
{ | ||
if ($this->taskRunner === null) { | ||
$this->taskRunner = new TaskRunner(); | ||
} | ||
return $this->taskRunner; | ||
} | ||
} |
Oops, something went wrong.