未加星标

Monitoring your Email Manager Queue with Sugar CLI

字体大小 | |
[开发(php) 所属分类 开发(php) | 发布者 店小二05 | 时间 2016 | 作者 红领巾 ] 0人收藏点击收藏

This post originally appeared on the SynoLab blog hosted by Synolia , an Elite SugarCRM Partner. This post describes how to extendthe new Sugar CLI framework to add commands that allow Sugar Administrators to monitor the Sugar e-mail queue.

Since the Sugar 7.7.1.0 version, SugarCRM introduced aSugar CLI tool based on Symfony Console . This Sugar CLI tool is under beta version at this moment (August 2016) and can be changed in the future.

We will see in this article how to use this new Sugar CLI to add a command which provides some statistics from the Email Manager Queue. We want to display how many emails by campaign by module are waiting to be sent.

The first step is to define the Command itself

To perform this operation we implement Sugarcrm\Sugarcrm\Console\CommandRegistry\Mode\InstanceModeInterface because our command must be executed only on an installed Sugar instance. The only required things to do is to providethe command name, the description, and the help text on the configure() method and then to implement our logic in the execute() method. We are using a SugarQuery to retrieve the data and display the result ona table. We can imagine externalizingthis part and using it in an API and creating unit tests.

//File: custom/Synolia/EmailMan/Console/Command/ListQueueCommand.php namespace Synolia\EmailMan\Console\Command; use Sugarcrm\Sugarcrm\Console\CommandRegistry\Mode\InstanceModeInterface; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Helper\Table; use Symfony\Component\Console\Helper\TableSeparator; /** * * Email Manager Queue statistics * */ class ListQueueCommand extends Command implements InstanceModeInterface { /** * {inheritdoc} */ protected function configure() { $this ->setName('synolia:emailman:queue') ->setDescription('Show Email Manager Queue statistics') ->setHelp('This command displays statistics from Email Manager Queue.') ; } /** * {inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { $result = $this->getSugarQuery()->execute(); $nbEmailsToSent = 0; $table = new Table($output); $table->setHeaders(array('Campaign', 'Module', 'Count')); foreach ($result as $row) { $table->addRow(array($row['name'], $row['related_type'], $row['record_count'])); $nbEmailsToSent += $row['record_count']; } $table->addRow(new TableSeparator()); $table->addRow(array('# Emails to send', '', $nbEmailsToSent)); $table->render(); } /** * @return \SugarQuery * @throws \SugarQueryException */ protected function getSugarQuery() { $sq = new \SugarQuery(); $sq->from(\BeanFactory::newBean('EmailMan')) ->joinTable('campaigns', array( 'alias' => 'campaigns', 'joinType' => 'LEFT', 'linkingTable' => true) )->on()->equalsField('campaigns.id', 'emailman.campaign_id'); $sq->select(array('campaigns.name', 'emailman.related_type'))->setCountQuery(); $sq->groupBy('campaigns.name') ->groupBy('emailman.related_type'); return $sq; } } Declare the Command

Now we need to make this command availableby using the application/Ext/Console framework:

//File: custom/Extension/application/Ext/Console/SynoliaEmailManListQueueCommand.php Sugarcrm\Sugarcrm\Console\CommandRegistry\CommandRegistry::getInstance() ->addCommand(new Synolia\EmailMan\Console\Command\ListQueueCommand()); Add our namespace

To use our own namespace we can follow one of the way described in our previous article by using the application/Ext/Utils framework:

//File: custom/Extension/application/Ext/Utils/SynoliaEmailManConsoleCommandNamespace.php SugarAutoLoader::addNamespace('Synolia\\EmailMan\\Console\\Command', 'custom/Synolia/EmailMan/Console/Command', 'psr4');

本文开发(php)相关术语:php代码审计工具 php开发工程师 移动开发者大会 移动互联网开发 web开发工程师 软件开发流程 软件开发工程师

主题: CRMSugarCRMHead
分页:12
转载请注明
本文标题:Monitoring your Email Manager Queue with Sugar CLI
本站链接:http://www.codesec.net/view/481573.html
分享请点击:


1.凡CodeSecTeam转载的文章,均出自其它媒体或其他官网介绍,目的在于传递更多的信息,并不代表本站赞同其观点和其真实性负责;
2.转载的文章仅代表原创作者观点,与本站无关。其原创性以及文中陈述文字和内容未经本站证实,本站对该文以及其中全部或者部分内容、文字的真实性、完整性、及时性,不作出任何保证或承若;
3.如本站转载稿涉及版权等问题,请作者及时联系本站,我们会及时处理。
登录后可拥有收藏文章、关注作者等权限...
技术大类 技术大类 | 开发(php) | 评论(0) | 阅读(41)