Skip to content

Commit

Permalink
Merge branch '4.1-dev' into j4/mce/paste
Browse files Browse the repository at this point in the history
  • Loading branch information
bembelimen committed Jan 9, 2022
2 parents c91670b + 1554ad2 commit 381cc9f
Show file tree
Hide file tree
Showing 17 changed files with 86 additions and 124 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,5 @@ INSERT INTO `#__action_log_config` (`type_title`, `type_alias`, `id_holder`, `ti
INSERT INTO `#__mail_templates` (`template_id`, `extension`, `language`, `subject`, `body`, `htmlbody`, `attachments`, `params`) VALUES
('plg_system_tasknotification.failure_mail', 'plg_system_tasknotification', '', 'PLG_SYSTEM_TASK_NOTIFICATION_FAILURE_MAIL_SUBJECT', 'PLG_SYSTEM_TASK_NOTIFICATION_FAILURE_MAIL_BODY', '', '', '{"tags": ["task_id", "task_title", "exit_code", "exec_data_time", "task_output"]}'),
('plg_system_tasknotification.fatal_recovery_mail', 'plg_system_tasknotification', '', 'PLG_SYSTEM_TASK_NOTIFICATION_FATAL_MAIL_SUBJECT', 'PLG_SYSTEM_TASK_NOTIFICATION_FATAL_MAIL_BODY', '', '', '{"tags": ["task_id", "task_title"]}'),
('plg_system_tasknotification.orphan_mail', 'plg_system_tasknotification', '', 'PLG_SYSTEM_TASK_NOTIFICATION_ORPHAN_MAIL_SUBJECT', 'PLG_SYSTEM_TASK_NOTIFICATION_ORPHAN_MAIL_BODY', '', '', '{"tags": ["task_id", "task_title", ""]}'),
('plg_system_tasknotification.orphan_mail', 'plg_system_tasknotification', '', 'PLG_SYSTEM_TASK_NOTIFICATION_ORPHAN_MAIL_SUBJECT', 'PLG_SYSTEM_TASK_NOTIFICATION_ORPHAN_MAIL_BODY', '', '', '{"tags": ["task_id", "task_title"]}'),
('plg_system_tasknotification.success_mail', 'plg_system_tasknotification', '', 'PLG_SYSTEM_TASK_NOTIFICATION_SUCCESS_MAIL_SUBJECT', 'PLG_SYSTEM_TASK_NOTIFICATION_SUCCESS_MAIL_BODY', '', '', '{"tags":["task_id", "task_title", "exec_data_time", "task_output"]}');
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
UPDATE `#__mail_templates`
SET `params` = '{"tags": ["task_id", "task_title"]}'
WHERE `template_id`= 'plg_system_tasknotification.orphan_mail' AND `params` = '{"tags": ["task_id", "task_title", ""]}';
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,5 @@ INSERT INTO "#__action_log_config" ("type_title", "type_alias", "id_holder", "ti
INSERT INTO "#__mail_templates" ("template_id", "extension", "language", "subject", "body", "htmlbody", "attachments", "params") VALUES
('plg_system_tasknotification.failure_mail', 'plg_system_tasknotification', '', 'PLG_SYSTEM_TASK_NOTIFICATION_FAILURE_MAIL_SUBJECT', 'PLG_SYSTEM_TASK_NOTIFICATION_FAILURE_MAIL_BODY', '', '', '{"tags": ["task_id", "task_title", "exit_code", "exec_data_time", "task_output"]}'),
('plg_system_tasknotification.fatal_recovery_mail', 'plg_system_tasknotification', '', 'PLG_SYSTEM_TASK_NOTIFICATION_FATAL_MAIL_SUBJECT', 'PLG_SYSTEM_TASK_NOTIFICATION_FATAL_MAIL_BODY', '', '', '{"tags": ["task_id", "task_title"]}'),
('plg_system_tasknotification.orphan_mail', 'plg_system_tasknotification', '', 'PLG_SYSTEM_TASK_NOTIFICATION_ORPHAN_MAIL_SUBJECT', 'PLG_SYSTEM_TASK_NOTIFICATION_ORPHAN_MAIL_BODY', '', '', '{"tags": ["task_id", "task_title", ""]}'),
('plg_system_tasknotification.orphan_mail', 'plg_system_tasknotification', '', 'PLG_SYSTEM_TASK_NOTIFICATION_ORPHAN_MAIL_SUBJECT', 'PLG_SYSTEM_TASK_NOTIFICATION_ORPHAN_MAIL_BODY', '', '', '{"tags": ["task_id", "task_title"]}'),
('plg_system_tasknotification.success_mail', 'plg_system_tasknotification', '', 'PLG_SYSTEM_TASK_NOTIFICATION_SUCCESS_MAIL_SUBJECT', 'PLG_SYSTEM_TASK_NOTIFICATION_SUCCESS_MAIL_BODY', '', '', '{"tags":["task_id", "task_title", "exec_data_time", "task_output"]}');
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
UPDATE "#__mail_templates"
SET "params" = '{"tags": ["task_id", "task_title"]}'
WHERE "template_id"= 'plg_system_tasknotification.orphan_mail' AND "params" = '{"tags": ["task_id", "task_title", ""]}';
38 changes: 2 additions & 36 deletions administrator/components/com_media/src/Model/ApiModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,13 @@
use Joomla\CMS\MVC\Model\BaseDatabaseModel;
use Joomla\CMS\Object\CMSObject;
use Joomla\CMS\Plugin\PluginHelper;
use Joomla\Component\Media\Administrator\Adapter\AdapterInterface;
use Joomla\Component\Media\Administrator\Event\FetchMediaItemEvent;
use Joomla\Component\Media\Administrator\Event\FetchMediaItemsEvent;
use Joomla\Component\Media\Administrator\Event\FetchMediaItemUrlEvent;
use Joomla\Component\Media\Administrator\Event\MediaProviderEvent;
use Joomla\Component\Media\Administrator\Exception\FileExistsException;
use Joomla\Component\Media\Administrator\Exception\FileNotFoundException;
use Joomla\Component\Media\Administrator\Exception\InvalidPathException;
use Joomla\Component\Media\Administrator\Provider\ProviderManager;
use Joomla\Component\Media\Administrator\Provider\ProviderManagerHelperTrait;

/**
* Api Model
Expand All @@ -34,13 +32,7 @@
*/
class ApiModel extends BaseDatabaseModel
{
/**
* Holds the available media file adapters.
*
* @var ProviderManager
* @since 4.0.0
*/
private $providerManager = null;
use ProviderManagerHelperTrait;

/**
* The available extensions.
Expand All @@ -50,32 +42,6 @@ class ApiModel extends BaseDatabaseModel
*/
private $allowedExtensions = null;

/**
* Return the requested adapter
*
* @param string $name Name of the provider
*
* @since 4.0.0
* @return AdapterInterface
*
* @throws \Exception
*/
private function getAdapter($name)
{
if ($this->providerManager == null)
{
$this->providerManager = new ProviderManager;

// Fire the event to get the results
$eventParameters = ['context' => 'AdapterManager', 'providerManager' => $this->providerManager];
$event = new MediaProviderEvent('onSetupProviders', $eventParameters);
PluginHelper::importPlugin('filesystem');
Factory::getApplication()->triggerEvent('onSetupProviders', $event);
}

return $this->providerManager->getAdapter($name);
}

/**
* Returns the requested file or folder information. More information
* can be found in AdapterInterface::getFile().
Expand Down
19 changes: 5 additions & 14 deletions administrator/components/com_media/src/Model/MediaModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,8 @@

\defined('_JEXEC') or die;

use Joomla\CMS\Factory;
use Joomla\CMS\MVC\Model\BaseDatabaseModel;
use Joomla\CMS\Plugin\PluginHelper;
use Joomla\Component\Media\Administrator\Event\MediaProviderEvent;
use Joomla\Component\Media\Administrator\Provider\ProviderManager;
use Joomla\Component\Media\Administrator\Provider\ProviderManagerHelperTrait;

/**
* Media View Model
Expand All @@ -24,6 +21,8 @@
*/
class MediaModel extends BaseDatabaseModel
{
use ProviderManagerHelperTrait;

/**
* Obtain list of supported providers
*
Expand All @@ -33,17 +32,9 @@ class MediaModel extends BaseDatabaseModel
*/
public function getProviders()
{
// Setup provider manager and event parameters
$providerManager = new ProviderManager;
$eventParameters = ['context' => 'AdapterManager', 'providerManager' => $providerManager];
$event = new MediaProviderEvent('onSetupProviders', $eventParameters);
$results = [];

// Import plugin group and fire the event
PluginHelper::importPlugin('filesystem');
Factory::getApplication()->triggerEvent('onSetupProviders', $event);
$results = [];

foreach ($providerManager->getProviders() as $provider)
foreach ($this->getProviderManager()->getProviders() as $provider)
{
$result = new \stdClass;
$result->name = $provider->getID();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/

namespace Joomla\Component\Media\Api\Helper;
namespace Joomla\Component\Media\Administrator\Provider;

\defined('_JEXEC') or die;

Expand All @@ -24,7 +24,7 @@
*
* @since 4.1.0
*/
trait AdapterTrait
trait ProviderManagerHelperTrait
{
/**
* Holds the available media file adapters.
Expand All @@ -45,40 +45,25 @@ trait AdapterTrait
private $defaultAdapterName = null;

/**
* Returns an array with the adapter name as key and the path of the file.
*
* @return array
* Return a provider manager.
*
* @throws \Exception
* @return ProviderManager
*
* @since 4.1.0
*/
private function resolveAdapterAndPath(String $path): array
public function getProviderManager(): ProviderManager
{
$result = [];
$parts = explode(':', $path, 2);

// If we have 2 parts, we have both an adapter name and a file path
if (\count($parts) == 2)
{
$result['adapter'] = $parts[0];
$result['path'] = $parts[1];

return $result;
}

if (!$this->getDefaultAdapterName())
if (!$this->providerManager)
{
throw new \InvalidArgumentException('No adapter found');
// Fire the event to get the results
$eventParameters = ['context' => 'AdapterManager', 'providerManager' => new ProviderManager];
$event = new MediaProviderEvent('onSetupProviders', $eventParameters);
PluginHelper::importPlugin('filesystem');
Factory::getApplication()->triggerEvent('onSetupProviders', $event);
$this->providerManager = $event->getProviderManager();
}

// If we have less than 2 parts, we return a default adapter name
$result['adapter'] = $this->getDefaultAdapterName();

// If we have 1 part, we return it as the path. Otherwise we return a default path
$result['path'] = \count($parts) ? $parts[0] : '/';

return $result;
return $this->providerManager;
}

/**
Expand All @@ -90,7 +75,7 @@ private function resolveAdapterAndPath(String $path): array
*
* @since 4.1.0
*/
private function getProvider(String $id): ProviderInterface
public function getProvider(String $id): ProviderInterface
{
return $this->getProviderManager()->getProvider($id);
}
Expand All @@ -104,11 +89,48 @@ private function getProvider(String $id): ProviderInterface
*
* @since 4.1.0
*/
private function getAdapter(String $name): AdapterInterface
public function getAdapter(String $name): AdapterInterface
{
return $this->getProviderManager()->getAdapter($name);
}

/**
* Returns an array with the adapter name as key and the path of the file.
*
* @return array
*
* @throws \InvalidArgumentException
*
* @since __DEPLOY_VERSION__
*/
protected function resolveAdapterAndPath(String $path): array
{
$result = [];
$parts = explode(':', $path, 2);

// If we have 2 parts, we have both an adapter name and a file path
if (\count($parts) === 2)
{
$result['adapter'] = $parts[0];
$result['path'] = $parts[1];

return $result;
}

if (!$this->getDefaultAdapterName())
{
throw new \InvalidArgumentException('No adapter found');
}

// If we have less than 2 parts, we return a default adapter name
$result['adapter'] = $this->getDefaultAdapterName();

// If we have 1 part, we return it as the path. Otherwise we return a default path
$result['path'] = \count($parts) ? $parts[0] : '/';

return $result;
}

/**
* Returns the default adapter name.
*
Expand All @@ -118,7 +140,7 @@ private function getAdapter(String $name): AdapterInterface
*
* @since 4.1.0
*/
private function getDefaultAdapterName(): ?string
protected function getDefaultAdapterName(): ?string
{
if ($this->defaultAdapterName)
{
Expand All @@ -143,27 +165,4 @@ private function getDefaultAdapterName(): ?string

return $this->defaultAdapterName;
}

/**
* Return a provider manager.
*
* @return ProviderManager
*
* @since 4.1.0
*/
private function getProviderManager(): ProviderManager
{
if (!$this->providerManager)
{
$this->providerManager = new ProviderManager;

// Fire the event to get the results
$eventParameters = ['context' => 'AdapterManager', 'providerManager' => $this->providerManager];
$event = new MediaProviderEvent('onSetupProviders', $eventParameters);
PluginHelper::importPlugin('filesystem');
Factory::getApplication()->triggerEvent('onSetupProviders', $event);
}

return $this->providerManager;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

use Joomla\CMS\MVC\Controller\ApiController;
use Joomla\Component\Media\Administrator\Exception\InvalidPathException;
use Joomla\Component\Media\Api\Helper\AdapterTrait;
use Joomla\Component\Media\Administrator\Provider\ProviderManagerHelperTrait;

/**
* Media web service controller.
Expand All @@ -22,7 +22,7 @@
*/
class AdaptersController extends ApiController
{
use AdapterTrait;
use ProviderManagerHelperTrait;

/**
* The content type of the item.
Expand Down
4 changes: 2 additions & 2 deletions api/components/com_media/src/Controller/MediaController.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
use Joomla\CMS\MVC\Controller\ApiController;
use Joomla\Component\Media\Administrator\Exception\FileExistsException;
use Joomla\Component\Media\Administrator\Exception\InvalidPathException;
use Joomla\Component\Media\Api\Helper\AdapterTrait;
use Joomla\Component\Media\Administrator\Provider\ProviderManagerHelperTrait;
use Joomla\Component\Media\Api\Model\MediumModel;
use Joomla\String\Inflector;
use Tobscure\JsonApi\Exception\InvalidParameterException;
Expand All @@ -30,7 +30,7 @@
*/
class MediaController extends ApiController
{
use AdapterTrait;
use ProviderManagerHelperTrait;

/**
* The content type of the item.
Expand Down
4 changes: 2 additions & 2 deletions api/components/com_media/src/Model/AdapterModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
\defined('_JEXEC') or die;

use Joomla\CMS\MVC\Model\BaseModel;
use Joomla\Component\Media\Api\Helper\AdapterTrait;
use Joomla\Component\Media\Administrator\Provider\ProviderManagerHelperTrait;

/**
* Media web service model supporting a single adapter item.
Expand All @@ -21,7 +21,7 @@
*/
class AdapterModel extends BaseModel
{
use AdapterTrait;
use ProviderManagerHelperTrait;

/**
* Method to get a single adapter.
Expand Down
4 changes: 2 additions & 2 deletions api/components/com_media/src/Model/AdaptersModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
use Joomla\CMS\MVC\Model\BaseModel;
use Joomla\CMS\MVC\Model\ListModelInterface;
use Joomla\CMS\Pagination\Pagination;
use Joomla\Component\Media\Api\Helper\AdapterTrait;
use Joomla\Component\Media\Administrator\Provider\ProviderManagerHelperTrait;

/**
* Media web service model supporting lists of media adapters.
Expand All @@ -23,7 +23,7 @@
*/
class AdaptersModel extends BaseModel implements ListModelInterface
{
use AdapterTrait;
use ProviderManagerHelperTrait;

/**
* A hacky way to enable the standard jsonapiView::displayList() to create a Pagination object,
Expand Down
4 changes: 2 additions & 2 deletions api/components/com_media/src/Model/MediaModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
use Joomla\CMS\Pagination\Pagination;
use Joomla\Component\Media\Administrator\Exception\FileNotFoundException;
use Joomla\Component\Media\Administrator\Model\ApiModel;
use Joomla\Component\Media\Api\Helper\AdapterTrait;
use Joomla\Component\Media\Administrator\Provider\ProviderManagerHelperTrait;

/**
* Media web service model supporting lists of media items.
Expand All @@ -27,7 +27,7 @@
*/
class MediaModel extends BaseModel implements ListModelInterface
{
use AdapterTrait;
use ProviderManagerHelperTrait;

/**
* Instance of com_media's ApiModel
Expand Down

0 comments on commit 381cc9f

Please sign in to comment.