How to remove already enqueued messages in joomla 2.5?
Thanks in advance!
I tried
$jAp = JFactory::getApplication();
$messagesexist = $jAp->getMessageQueue();
But the above code is showing all the enqued messages.
From that I want to remove particular message.
Try this,
$session = JFactory::getSession();
$sessionQueue = $session->get('application.queue');
if (count($sessionQueue)) {
$session->set('application.queue', null);
}
Hope its works..
To remove a particular message you will have to work through the array returned by getMessageQueue().
So something like this:
// Get the message queue
$messages = JFactory::getApplication()->getMessageQueue();
// If we have messages
if (is_array($messages) && count($messages))
{
// Check each message for the one we want
foreach ($messages as $message)
{
// do your checks here
}
}
Related
I have the script below which is used to send messages (sms, email & whatsapp) to some 300k customers. Things where working fine before but for some days now the script is bugging (it freezes at some point in the loop. I can see this with the progress bar which doesn't move further). I have checked laravel.log and there is no particular error message. The script itself does not output any error message.
Below is the code:
/**
* Execute the console command.
*
* #return mixed
*/
public function handle()
{
AccountsCstm::where('authentification_c', 1)->chunk(10000, function ($customer_details) {
$bar = $this->output->createProgressBar(count($customer_details));
$bar->start();
foreach ($customer_details as $customer_detail) {
// Get customer bills and send through the appropriate channel. He could have multiple bills
if (isset($customer_detail->account->sic_code)) {
$bills = TbBillsInfos::where('contract_number', $customer_detail->account->sic_code)->where('bill_status', 'UNPAID')->get();
if (isset($bills)){
foreach ($bills as $bill) {
// Send messages.
if ($customer_detail->is_whatsapp_c) {
$message = $this->bill_message($customer_detail, $bill, 'WhatsApp');
// Send the message
$this->send_whatsapp_message($customer_detail->phone_4_c, $message, $customer_detail->contract_number_c);
// Record the message in database
$this->save_message('WhatsApp', $customer_detail->phone_4_c, null, $message, $customer_detail->account->id);
} elseif ($customer_detail->is_sms_c) {
$message = $this->bill_message($customer_detail, $bill, 'SMS');
// Send the message
$this->send_sms($customer_detail->phone_4_c, $message);
// Record the message in database
$this->save_message('SMS', $customer_detail->phone_4_c, null, $message, $customer_detail->account->id);
} elseif ($customer_detail->is_mail_c) {
$message = $this->bill_message($customer_detail, $bill, 'Email');
// Send the message
$this->send_email($customer_detail, $bill, $message);
// Record the message in database
$this->save_message('Email', null, $customer_detail->mail_c, $message, $customer_detail->account->id);
}
}
}
}
$bar->advance();
}
$bar->finish();
});
// Delete all record from the tb_bills_infos table
// Set the auto-increment value to 0
TbBillsInfos::truncate();
Log::info('send:unpaid-bill-messages: Command executed successfully');
}
Please can someone point out what can be the issue with the above script? Why is it bugging and not completing execution ? Why is it freezing at some point in the loop?
See for example the command since April 21, where as before it will complete execution in about 15 minutes or less
I have equally checked RAM usage on the server and only 1GB out of 8GB is being used. So the server is stable
I am trying to store heavy image through the laravel queue as follows because i dont want my user to wait until file gets stored:
This code is in controller
if($request->hasfile('featuringPhoto'))
{
$prefixFilename = date("Y-m-d-H-i-s");
$coverFilename = $prefixFilename.$request->featuringPhoto->getClientOriginalName();
ProceessFiles::dispatch($request->featuringPhoto->getRealPath(),$coverFilename);
}
else
{
$coverFilename4 = NULL;
}
Below code is in job
protected $files, $filename;
public function __construct($files,$filename)
{
$this->files= $files;
$this->filename = $filename;
}
public function handle()
{
if($this->files){
$coverFilename = $prefixFilename.$this->filename;
$img = file_get_contents($this->files);
$img->storeAs('images/photosUploadedByUser', $coverFilename, 'public');
}
}
It Gives me an error saying Call to a member function storeAs() on string
I tried this solution from stack but didnt work
Any suggestion will be appreciated.Thank you.
I think it is wrong to assume you are gonna save a lot time by executing the save operation in a queue, also because you are already fetching it from the web server. Queues will with scaling often be moved to worker servers and with this approach this will not work.
In the spirit of the question, stackoverflow and to explain to you what is not working. file_get_contents() returns the content of the file as a string. So to fix your problem, you should just store the results of that. You obviously can not call methods on strings.
$coverFilename = $prefixFilename.$this->filename;
$img = file_get_contents($this->files);
Storage::put('images/photosUploadedByUser/' . $coverFilename, $img);
I want to email a potentially large number of clients, so I am using Batches and pushing each email send as a batched job, like this:
public function __construct(RunReport $runReport, User $run_by) {
$this->runReport = $runReport;
$this->run_by = $run_by;
}
public function handle()
{
$company_detail = CompanyDetail::first();
$jobs = $this->runReport->runReportReportees
->map(fn(RunReportReportee $runReportReportee) => new EmailStatementJob($runReportReportee, $company_detail))
->toArray();
$batch = Bus
::batch($jobs)
->then(function(Batch $batch) {
// All completed
$completed = ($batch->totalJobs - $batch->failedJobs);
$message = "foo";
$type = "bar";
$this->run_by->notify(new GenericNotification($message, $type, 'envelope'));
})
->allowFailures()
->name('Batch name here trust me')
->dispatch();
return $batch->id;
}
However the notify line causes an error Serialization of 'Doctrine\DBAL\Driver\PDOConnection' is not allowed.
How can I notify the user that initiated the batch when the batch is finished, with the results of the included email send attempts? Alternatively, how else should I email a few hundred clients and notify the user of the results?
I figured it out eventually with help - I was using $this in the ->then() callback which was my first mistake. Then instead of the notification in the job, I have instead stored the user ID and passed it to the then() callback like this
->then(function(Batch $batch) use ($run_by_id) { ... }
In the callback instead of notifying the user, I call an event
event(new HcpStatementsBatchFinishedEvent($batch, $id));
The event simply stores the information
public function __construct(Batch $batch, int $run_by_sysid)
{
$this->run_by = User::find($run_by_id);
$this->batch = $batch;
}
And the listener for the event builds the message and notifies the user.
I'm having an issue with this route and not sure what my problem is exactly.
My page is located at http://www.kansasoutlawwrestling.com/kowmanager/pmsystem/viewmessage/1 where 1 is the message id.
I set up a route to look like
$route['pmsystem/viewmessage/(:num)'] = 'pmsystem/viewmessage/$1';
and I'm still getting a error message like this
A PHP Error was encountered
Severity: Warning
Message: Missing argument 1 for Pmsystem::viewmessage()
Filename: controllers/pmsystem.php
Line Number: 76
// View A Message
function viewmessage($message_id)
{
//Config Defaults Start
$msgBoxMsgs = array();//msgType = dl, info, warn, note, msg
$cssPageAddons = '';//If you have extra CSS for this view append it here
$jsPageAddons = '<script src='.base_url().'../assets/js/cpanel/personalmessages.js></script><script src='.base_url().'assets/js/mylibs/jwysiwyg/jquery.wysiwyg.js></script>';//If you have extra JS for this view append it here
$metaAddons = '';//Sometimes there is a need for additional Meta Data such in the case of Facebook addon's
$siteTitle = '';//alter only if you need something other than the default for this view.
//Config Defaults Start
//examples of how to use the message box system (css not included).
//$msgBoxMsgs[] = array('msgType' => 'dl', 'theMsg' => 'This is a Blank Message Box...');
/**********************************************************Your Coding Logic Here, Start*/
// Checks to see if a session is active for user and shows corresponding view page
if (!$this->loggedin->chkLoginStatus() === FALSE)
{
if( ! $this->uri->segment(3))
{
redirect('error', 'refresh');
}
}
else
{
redirect('login', 'refresh');
}
$bodyContent = 'viewpm';//which view file
$bodyType = "full";//type of template
/***********************************************************Your Coding Logic Here, End*/
//Double checks if any default variables have been changed, Start.
//If msgBoxMsgs array has anything in it, if so displays it in view, else does nothing.
if(count($msgBoxMsgs) !== 0)
{
$msgBoxes = $this->msgboxes->buildMsgBoxesOutput(array('display' => 'show', 'msgs' =>$msgBoxMsgs));
}
else
{
$msgBoxes = array('display' => 'none');
}
if($siteTitle == '')
{
$siteTitle = $this->metatags->SiteTitle(); //reads
}
//Double checks if any default variables have been changed, End.
$this->data['msgBoxes'] = $msgBoxes;
$this->data['cssPageAddons'] = $cssPageAddons;//if there is any additional CSS to add from above Variable this will send it to the view.
$this->data['jsPageAddons'] = $jsPageAddons;//if there is any addictional JS to add from the above variable this will send it to the view.
$this->data['metaAddons'] = $metaAddons;//if there is any addictional meta data to add from the above variable this will send it to the view.
$this->data['pageMetaTags'] = $this->metatags->MetaTags();//defaults can be changed via models/metatags.php
$this->data['siteTitle'] = $siteTitle;//defaults can be changed via models/metatags.php
$this->data['bodyType'] = $bodyType;
$this->data['bodyContent'] = $bodyContent;
$this->data['user_data'] = $this->users->getUserByUserId($this->session->userdata('user_id'));
$this->data['users'] = $this->loggedin->getUserList();
$this->data['personal_messages'] = array($this->pmmodel->getTotalMessages($this->session->userdata('user_id')), $this->pmmodel->getTotalUnreadMessages($this->session->userdata('user_id')), $this->pmmodel->getLast5Messages($this->session->userdata('user_id')));
$this->data['messages'] = array($this->pmmodel->getInboxMessages($this->session->userdata('user_id')), $this->pmmodel->getSentMessages($this->session->userdata('user_id')));
//$this->data['message_data'] = $this->pmmodel->getPmMessage($this->uri->segment(3));
$this->load->view('cpanel/index', $this->data);
}
UPDATE
// Checks to see if a session is active for user and shows corresponding view page
if (!$this->loggedin->chkLoginStatus() === FALSE)
{
if (!is_numeric($this->uri->segment(3)))
{
$this->data['message_data'] = 'Invalid message id!';
}
else
{
$this->data['message_data'] = $this->pmmodel->getPmMessage($this->uri->segment(3));
}
$bodyContent = 'viewpm';//which view file
}
else
{
redirect('login', 'refresh');
}
$bodyType = "full";//type of template
This route is unnecessary - it doesn't change anything.
$route['pmsystem/viewmessage/(:num)'] = 'pmsystem/viewmessage/$1';
You can remove that route. The problem is here:
function viewmessage($message_id) // no default value means it's required
{
// your code
}
Your controller methods literally accept user input as arguments (whatever's in the address bar). You always have to account for those required arguments not being present in CI controller methods.
function viewmessage($message_id = NULL)
{
if ( ! $message_id) show_404();
// your code
}
This will silence the errors and show a 404 if the required $message_id is not there. Additionally, $this->uri->segment(3) is unnecessary because it should have the same value as $message_id.
I highly discourage redirecting to an error page when you really want a 404, but that's up to you. It sure doesn't help the user realize their mistake when the address is lost after the redirect, and you're sending the wrong HTTP headers by doing so.
Is there a way to programmatically reopen an order in Magento that has already reached complete or closed status? I have the following code which works for changing the status of an order, but I can't get it to work for complete or closed orders.
// connect to magento
require_once('app/Mage.php');
umask(022);
Mage::app();
// check admin credentials
Mage::getSingleton('core/session', array('name' => 'adminhtml'));
$admin = Mage::getSingleton('admin/session');
if ( $admin->isLoggedIn() ) {
// update order status
$orderIncrementId = "100000001";
$order = Mage::getModel('sales/order')->loadByIncrementId($orderIncrementId);
$order->setState(Mage_Sales_Model_Order::STATE_PROCESSING, true)->save();
}
I got the current code here. On that page it says that it was tested with Magento 1.3.2.4, but I'm using Magento 1.6.x. Maybe that's the issue?
Let me know if I need to provide more detail, and thanks for any help you can offer.
I don't think that you're having a Magento version issue here.
Under specific circumstances Magento simply just does not allow to switch the state of an order back to Mage_Sales_Model_Order::STATE_PROCESSING.
For example, usually you cannot save a Mage_Sales_Model_Order::STATE_PROCESSING state to any order, which already has had refunds (creditmemos). Neither in 1.3.2.4, nor in 1.6.x.
This is by-design.
Look at Mage_Sales_Model_Order::_checkState() to see under which circumstances Magento forces resetting the order state to STATE_COMPLETE or STATE_CLOSED, respectively.
protected function _checkState()
{
if (!$this->getId()) {
return $this;
}
$userNotification = $this->hasCustomerNoteNotify() ? $this->getCustomerNoteNotify() : null;
if (!$this->isCanceled()
&& !$this->canUnhold()
&& !$this->canInvoice()
&& !$this->canShip()) {
if (0 == $this->getBaseGrandTotal() || $this->canCreditmemo()) {
if ($this->getState() !== self::STATE_COMPLETE) {
$this->_setState(self::STATE_COMPLETE, true, '', $userNotification);
}
}
/**
* Order can be closed just in case when we have refunded amount.
* In case of "0" grand total order checking ForcedCanCreditmemo flag
*/
elseif (floatval($this->getTotalRefunded()) || (!$this->getTotalRefunded()
&& $this->hasForcedCanCreditmemo())
) {
if ($this->getState() !== self::STATE_CLOSED) {
$this->_setState(self::STATE_CLOSED, true, '', $userNotification);
}
}
}
if ($this->getState() == self::STATE_NEW && $this->getIsInProcess()) {
$this->setState(self::STATE_PROCESSING, true, '', $userNotification);
}
return $this;
}
To answer your question: you could achieve what you're trying to do by overriding the _checkState() method with your own method, which allows to set STATE_PROCESSING.
Be aware though, that this most probably will cause the creation of new state contexts which Magento neither knows nor expects or can handle.
If your changes wreak havoc, don't blame me. You've been warned^^