Running command line?

Jonny Balfour

New Member
Hi,

A couple questions i have:

1. I saw in another thread about deleting inactive leads who have not opened in the last 90
days, BUT also were not added within the last 90 days. I've downloaded the command line
that was given which apparently works great. My questions is though, how do i actually run
a command line? Im not techy ha!

2. Is there a way to delete unsubscribes without having to go through every single page? I have
600 to delete, it will take me forever running through 10 leads per page.

Thanks, look forward to your response.

Jonny
 
@Jonny Balfour
#1 - You run a command like:
Code:
/usr/bin/php -q /absolute/path/to/apps/console/console.php the-command-name-here
If you run just:
Code:
/usr/bin/php -q /absolute/path/to/apps/console/console.php
You will see a list with all commands you can run.

#2 - Go to Backend > Settings > Cron > Subscriber Settings, and set how many days mailwizz should keep these in the system, then mailwizz will remove them automatically.
 
Hi,

Thanks a lot.

I've set the unsubscribe feature up.

But for the command line, I'm gonna make myself look more stupid, but I've literally no idea
where to run a command, as in literally where in the backoffice do i go to paste this command line in?

This is the one i got from another post:

<?php defined('MW_PATH') || exit('No direct script access allowed');

/**
* DeleteInactiveSubscribersCommand
*
* @package MailWizz EMA
* @author Serban George Cristian <cristian.serban@mailwizz.com>
* @link http://www.mailwizz.com/
* @copyright 2013-2017 MailWizz EMA (http://www.mailwizz.com)
* @license http://www.mailwizz.com/license/
* @since 1.3.7.1
*/

class DeleteInactiveSubscribersCommand extends ConsoleCommand
{
public function actionIndex($list_uid, $time, $limit = 1000)
{
if (empty($list_uid)) {
$this->stdout('Please set the list UID by using the --list_uid flag!');
return 0;
}

if (empty($time)) {
$this->stdout('Please set the time using the --time flag!');
return 0;
}

$list = Lists::model()->findByAttributes(array(
'list_uid' => $list_uid,
));

if (empty($list)) {
$this->stdout('We cannot find the source list by it\'s UID!');
return 0;
}

$count = $inactive = $success = $error = 0;
$criteria = new CDbCriteria();
$criteria->compare('t.list_id', $list->list_id);
$criteria->compare('t.status', ListSubscriber::STATUS_CONFIRMED);
$criteria->compare('DATE(t.date_added)', '<=' . date('Y-m-d', strtotime($time)));
$criteria->limit = (int)$limit;

$subscribersNotIn = array();
$subscribers = ListSubscriber::model()->findAll($criteria);
while (!empty($subscribers)) {

foreach ($subscribers as $subscriber) {

$count++;

$this->stdout(sprintf('Checking: "%s"...', $subscriber->email));

// did the subscriber received any campaign at all?
$sql = 'SELECT subscriber_id FROM {{campaign_delivery_log}} WHERE subscriber_id = :sid AND DATE(date_added) >= :da LIMIT 1';
$row = Yii::app()->getDb()->createCommand($sql)->queryRow(true, array(
':sid' => $subscriber->subscriber_id,
':da' => date('Y-m-d', strtotime($time)),
));
$campaignDeliveryLog = !empty($row['subscriber_id']);
$campaignDeliveryLogArchive = false;

if (!$campaignDeliveryLog) {
$sql = 'SELECT subscriber_id FROM {{campaign_delivery_log_archive}} WHERE subscriber_id = :sid AND DATE(date_added) >= :da LIMIT 1';
$row = Yii::app()->getDb()->createCommand($sql)->queryRow(true, array(
':sid' => $subscriber->subscriber_id,
':da' => date('Y-m-d', strtotime($time)),
));
$campaignDeliveryLogArchive = !empty($row['subscriber_id']);
}

if (!$campaignDeliveryLog && !$campaignDeliveryLogArchive) {
$subscribersNotIn[] = $subscriber->subscriber_id;
$this->stdout(sprintf('No campaign was ever sent to "%s".', $subscriber->email));
continue;
}
//

// did the subscriber opened a campaign?
$sql = 'SELECT subscriber_id FROM {{campaign_track_open}} WHERE subscriber_id = :sid AND DATE(date_added) >= :da LIMIT 1';
$row = Yii::app()->getDb()->createCommand($sql)->queryRow(true, array(
':sid' => $subscriber->subscriber_id,
':da' => date('Y-m-d', strtotime($time)),
));
$hasOpened = !empty($row['subscriber_id']);

if (empty($hasOpened)) {

// did the subscriber clicked a campaign?
$sql = 'SELECT subscriber_id FROM {{campaign_track_url}} WHERE subscriber_id = :sid AND DATE(date_added) >= :da LIMIT 1';
$row = Yii::app()->getDb()->createCommand($sql)->queryRow(true, array(
':sid' => $subscriber->subscriber_id,
':da' => date('Y-m-d', strtotime($time)),
));
$hasClicked = !empty($row['subscriber_id']);
}

if (!empty($hasOpened) || !empty($hasClicked)) {
$subscribersNotIn[] = $subscriber->subscriber_id;
$this->stdout(sprintf('"%s" has opened/clicked at least one campaign in the given period of time.', $subscriber->email));
continue;
}

$inactive++;

if ($subscriber->delete()) {
$success++;
$this->stdout(sprintf('[SUCCESS] "%s" has been deleted!', $subscriber->email));
} else {
$error++;
$this->stdout(sprintf('[FAIL] "%s" could not be deleted!', $subscriber->email));
}
}

$_criteria = clone $criteria;
if (!empty($subscribersNotIn)) {
$subscribersNotIn = array_unique($subscribersNotIn);
$_criteria->addNotInCondition('subscriber_id', $subscribersNotIn);
}
$subscribers = ListSubscriber::model()->findAll($_criteria);
}

$this->stdout(sprintf('Done processing %d subscribers out of which %d were inactive from which %d were deleted successfully and %d had errors!', $count, $inactive, $success, $error));
return 0;
}

public function getHelp()
{
$cmd = $this->getCommandRunner()->getScriptName() .' '. $this->getName();

$help = sprintf('command: %s --list_uid=LIST_UID --time=EXPRESSION --limit=1000', $cmd) . "\n";
$help .= '--list_uid=UID where UID is the list unique 13 chars id from where you want to delete subscribers.' . "\n";
$help .= '--time=EXPRESSION where EXPRESSION can be any expression parsable by php\'s strtotime function. ie: --time="-6 months".' . "\n";
$help .= '--limit=1000 where 1000 is the number of subscribers to process at once.' . "\n";

return $help;
}
}



Is this still the correct one to use for my query?

Thanks again
Jonny
 
Ahh right, yes i have access to everything on my server.

I'll search how to get access to this, then do i literally copy paste the code i added above
and run this?

Also am i able to change subscriber un-opens/added date 30 days instead of the 90 i think i read it was for?
 
then do i literally copy paste the code i added above
No, of course not.

Go in backend > misc > cron jobs list and see how the cron job for send-campaigns looks like, in my case it is:
Code:
* * * * * /usr/bin/php -q /var/www/vhosts/domain.mailwizz.com/httpdocs/web/apps/console/console.php send-campaigns >/dev/null 2>&1

Which tells me that in order to run the command for removing delete inactive subscribers i have to run this:
Code:
/usr/bin/php -q /var/www/vhosts/domain.mailwizz.com/httpdocs/web/apps/console/console.php delete-inactive-subscribers --list_uid=YOUR_LIST_UID --time="-30 days" --verbose=1
 
Ok thanks, so to confirm, this bottom piece of code would delete people who have not opened ANY campaigns
within the last 30 days, PLUS who were added "on or before" 30 days ago?
 
Back
Top