Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
105 changes: 101 additions & 4 deletions src/cli/tjqueue.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@

use TJQueue\Admin\TJQueueConsume;
use Joomla\CMS\Log\Log;
use Joomla\CMS\Application\CliApplication;
use Joomla\CMS\Plugin\PluginHelper;
use Joomla\CMS\Factory;

define('_JEXEC', 1);
define('JPATH_BASE', dirname(__DIR__));
Expand All @@ -23,17 +26,53 @@
require_once JPATH_BASE . '/includes/defines.php';
}


// Check for presence of vendor dependencies not included in the git repository
if (!file_exists(JPATH_LIBRARIES . '/vendor/autoload.php') || !is_dir(JPATH_ROOT . '/media/vendor')) {
echo file_get_contents(JPATH_ROOT . '/templates/system/build_incomplete.html');
exit;
}

require_once JPATH_BASE . '/includes/framework.php';

// Boot the DI container
$container = \Joomla\CMS\Factory::getContainer();

// Alias the session service keys to the web session service as that is the primary session backend for this application
// In addition to aliasing "common" service keys, we also create aliases for the PHP classes to ensure autowiring objects is supported. This includes aliases for aliased class names, and the keys for aliased class names should be considered deprecated to be removed when the class name alias is removed as well.
$container->alias('session.web', 'session.web.site')
->alias('session', 'session.web.site')
->alias('JSession', 'session.web.site')
->alias(\Joomla\CMS\Session\Session::class, 'session.web.site')
->alias(\Joomla\Session\Session::class, 'session.web.site')
->alias(\Joomla\Session\SessionInterface::class, 'session.web.site');

// Instantiate the application.
$app = $container->get(\Joomla\CMS\Application\SiteApplication::class);

// Set the application as global app
\Joomla\CMS\Factory::$application = $app;

$app->createExtensionNamespaceMap();

// Get the framework.
require_once JPATH_LIBRARIES . '/import.legacy.php';
require_once JPATH_LIBRARIES . '/bootstrap.php';

// Bootstrap the CMS libraries.
require_once JPATH_LIBRARIES . '/cms.php';
// require_once JPATH_LIBRARIES . '/cms.php';

// Load the configuration
require_once JPATH_CONFIGURATION . '/configuration.php';

jimport('tjqueueconsume', JPATH_SITE . '/administrator/components/com_tjqueue/libraries');

require_once JPATH_BASE . '/includes/defines.php';
require_once JPATH_BASE . '/includes/framework.php';


//~ $app = Factory::getContainer()->get(\Joomla\CMS\Application\SiteApplication::class);
//~ $app->initialise();

/**
* TjQueue
*
Expand Down Expand Up @@ -74,21 +113,67 @@ public function __construct()
);

$argv = getopt($shortopts, $longopts);

$this->options = new stdClass;
$this->options->topic = array_key_exists('t', $argv) ? $argv['t'] : (array_key_exists('topic', $argv) ? $argv['topic'] : null);
$this->options->limit = array_key_exists('n', $argv) ? $argv['n'] : 50;
$this->options->timeout = array_key_exists('s', $argv) ? $argv['s'] : (array_key_exists('timeout', $argv) ? $argv['timeout'] : 2000);
}

/**
* Load an object or array into the application configuration object.
*
* @param mixed $data Either an array or object to be loaded into the configuration object.
*
* @return CliApplication Instance of $this to allow chaining.
*
* @since 1.7.0
*/
public function loadConfiguration($data)
{
// Load the data into the configuration object.
if (is_array($data))
{
$this->config->loadArray($data);
}
elseif (is_object($data))
{
$this->config->loadObject($data);
}

return $this;
}

/**
* Entry point for the script
*
* @return void
*
* @since 3.8.6
*/
// public function doExecute()
// {

// }
public function getName()
{

}

/**
* Method to execute script
*
* @return void.
*
* @since 1.0
*/
public function execute()
public function doExecute()
{
PluginHelper::importPlugin('system');
Joomla\CMS\Factory::getApplication()->triggerEvent('onAfterInitialise');

//PluginHelper::importPlugin('system');

$log['success'] = 1;
$log['message'] = 'Started: Running queue cron';
self::writeLog($log);
Expand Down Expand Up @@ -147,8 +232,20 @@ public function execute()
continue;
}

$mailcatcherFilePath = JPATH_SITE . '/plugins/system/mailcatcher/mailer.php';

if (!file_exists($mailcatcherFilePath))
{
$log['success'] = 0;
$log['message'] = "Error 404- mailcatcher class file doesn't exist:" . $mailcatcherFilePath;
self::writeLog($log);
continue;
}


try
{
require_once $mailcatcherFilePath;
require_once $filePath;

// Prepare class Name
Expand Down Expand Up @@ -240,7 +337,7 @@ function ($v, $k)
array($category = 'tjlogs')
);

$priority = $data['success'] == 1 ? JLog::INFO : JLog::ERROR;
$priority = $data['success'] == 1 ? Log::INFO : Log::ERROR;
Log::add($logMessage, $priority, $category = 'tjlogs');
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/com_tjqueue/admin/libraries/helpers/tjqueuecontext.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@

// SQS
use Enqueue\Sqs\SqsConnectionFactory;
use Joomla\CMS\Factory;

defined('JPATH_PLATFORM') or die;
jimport('joomla.filesystem.folder');
jimport('joomla.application.component.helper');

/**
* TJQueue Config
Expand All @@ -43,7 +43,7 @@ class TJQueueContext
protected function __construct()
{
$this->params = ComponentHelper::getParams('com_tjqueue');
$this->jconfig = \JFactory::getConfig();
$this->jconfig = Factory::getConfig();
}

/**
Expand Down
7 changes: 5 additions & 2 deletions src/com_tjqueue/admin/tjqueue.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,15 @@

// No direct access to this file
defined('_JEXEC') or die('Restricted access');
use Joomla\CMS\MVC\Controller\BaseController;
use Joomla\CMS\Factory;

// Get an instance of the controller prefixed by HelloWorld
$controller = JControllerLegacy::getInstance('Tjqueue');
$controller = BaseController::getInstance('Tjqueue');

// Perform the Request task
$controller->execute(JFactory::getApplication()->input->get('task'));
$controller->execute(Factory::getApplication()->input->get('task'));

// Redirect if set by the controller
$controller->redirect();

3 changes: 2 additions & 1 deletion src/com_tjqueue/admin/views/entries/view.html.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@

// No direct access to this file
defined('_JEXEC') or die('Restricted access');
use Joomla\CMS\MVC\View\HtmlView;

/**
* TJQueue View
*
* @since 0.0.1
*/
class TjqueueViewEntries extends JViewLegacy
class TjqueueViewEntries extends HtmlView
{
/**
* Display the Queues view
Expand Down
3 changes: 2 additions & 1 deletion src/plugins/tjqueue/core/consumers/email.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

// No direct access
defined('_JEXEC') or die;
use Joomla\CMS\Factory;

/**
* TjQueue
Expand Down Expand Up @@ -39,7 +40,7 @@ public function consume($message)
if (isset($recipients))
{
// Invoke JMail Class
$mailer = \JFactory::getMailer();
$mailer = \Factory::getMailer();

// Set cc for email
if (isset($content->cc))
Expand Down