Convert variable names to camel case

[MAILPOET-1796]
This commit is contained in:
Jan Jakeš
2020-01-09 15:02:58 +01:00
committed by Jan Jakeš
parent f5da704106
commit 54549ff037
687 changed files with 15890 additions and 15887 deletions

View File

@@ -19,8 +19,8 @@ class InactiveSubscribersController {
/** @var SettingsRepository */
private $settings_repository;
public function __construct(SettingsRepository $settings_repository) {
$this->settings_repository = $settings_repository;
public function __construct(SettingsRepository $settingsRepository) {
$this->settingsRepository = $settingsRepository;
}
/**
@@ -28,9 +28,9 @@ class InactiveSubscribersController {
* @param int $batch_size
* @return int|boolean
*/
public function markInactiveSubscribers($days_to_inactive, $batch_size, $start_id = null) {
$threshold_date = $this->getThresholdDate($days_to_inactive);
return $this->deactivateSubscribers($threshold_date, $batch_size, $start_id);
public function markInactiveSubscribers($daysToInactive, $batchSize, $startId = null) {
$thresholdDate = $this->getThresholdDate($daysToInactive);
return $this->deactivateSubscribers($thresholdDate, $batchSize, $startId);
}
/**
@@ -38,29 +38,29 @@ class InactiveSubscribersController {
* @param int $batch_size
* @return int
*/
public function markActiveSubscribers($days_to_inactive, $batch_size) {
$threshold_date = $this->getThresholdDate($days_to_inactive);
return $this->activateSubscribers($threshold_date, $batch_size);
public function markActiveSubscribers($daysToInactive, $batchSize) {
$thresholdDate = $this->getThresholdDate($daysToInactive);
return $this->activateSubscribers($thresholdDate, $batchSize);
}
/**
* @return void
*/
public function reactivateInactiveSubscribers() {
$reactivate_all_inactive_query = sprintf(
$reactivateAllInactiveQuery = sprintf(
"UPDATE %s SET status = '%s' WHERE status = '%s';",
Subscriber::$_table, Subscriber::STATUS_SUBSCRIBED, Subscriber::STATUS_INACTIVE
);
ORM::rawExecute($reactivate_all_inactive_query);
ORM::rawExecute($reactivateAllInactiveQuery);
}
/**
* @param int $days_to_inactive
* @return Carbon
*/
private function getThresholdDate($days_to_inactive) {
private function getThresholdDate($daysToInactive) {
$now = new Carbon();
return $now->subDays($days_to_inactive);
return $now->subDays($daysToInactive);
}
/**
@@ -68,28 +68,28 @@ class InactiveSubscribersController {
* @param int $batch_size
* @return int|boolean
*/
private function deactivateSubscribers(Carbon $threshold_date, $batch_size, $start_id = null) {
$subscribers_table = Subscriber::$_table;
$scheduled_tasks_table = ScheduledTask::$_table;
$scheduled_task_subcribres_table = ScheduledTaskSubscriber::$_table;
$statistics_opens_table = StatisticsOpens::$_table;
$sending_queues_table = SendingQueue::$_table;
private function deactivateSubscribers(Carbon $thresholdDate, $batchSize, $startId = null) {
$subscribersTable = Subscriber::$_table;
$scheduledTasksTable = ScheduledTask::$_table;
$scheduledTaskSubcribresTable = ScheduledTaskSubscriber::$_table;
$statisticsOpensTable = StatisticsOpens::$_table;
$sendingQueuesTable = SendingQueue::$_table;
$threshold_date_iso = $threshold_date->toDateTimeString();
$day_ago = new Carbon();
$day_ago_iso = $day_ago->subDay()->toDateTimeString();
$thresholdDateIso = $thresholdDate->toDateTimeString();
$dayAgo = new Carbon();
$dayAgoIso = $dayAgo->subDay()->toDateTimeString();
// If MP2 migration occurred during detection interval we can't deactivate subscribers
// because they are imported with original subscription date but they were not present in a list for whole period
$mp2_migration_date = $this->getMP2MigrationDate();
if ($mp2_migration_date && $mp2_migration_date > $threshold_date) {
$mp2MigrationDate = $this->getMP2MigrationDate();
if ($mp2MigrationDate && $mp2MigrationDate > $thresholdDate) {
return false;
}
// We take into account only emails which have at least one opening tracked
// to ensure that tracking was enabled for the particular email
if (!$this->inactives_task_ids_table_created) {
$inactives_task_ids_table = sprintf("
if (!$this->inactivesTaskIdsTableCreated) {
$inactivesTaskIdsTable = sprintf("
CREATE TEMPORARY TABLE IF NOT EXISTS inactives_task_ids
(INDEX task_id_ids (id))
SELECT DISTINCT task_id as id FROM $sending_queues_table as sq
@@ -102,16 +102,16 @@ class InactiveSubscribersController {
WHERE so.created_at > '%s'
AND so.newsletter_id = sq.newsletter_id
)",
$threshold_date_iso, $day_ago_iso, $threshold_date_iso
$thresholdDateIso, $dayAgoIso, $thresholdDateIso
);
ORM::rawExecute($inactives_task_ids_table);
$this->inactives_task_ids_table_created = true;
ORM::rawExecute($inactivesTaskIdsTable);
$this->inactivesTaskIdsTableCreated = true;
}
// Select subscribers who received a recent tracked email but didn't open it
$start_id = (int)$start_id;
$end_id = $start_id + $batch_size;
$inactive_subscriber_ids_tmp_table = 'inactive_subscriber_ids';
$startId = (int)$startId;
$endId = $startId + $batchSize;
$inactiveSubscriberIdsTmpTable = 'inactive_subscriber_ids';
ORM::rawExecute("
CREATE TEMPORARY TABLE IF NOT EXISTS $inactive_subscriber_ids_tmp_table
(UNIQUE subscriber_id (id))
@@ -119,33 +119,33 @@ class InactiveSubscribersController {
JOIN $scheduled_task_subcribres_table as sts USE INDEX (subscriber_id) ON s.id = sts.subscriber_id
JOIN inactives_task_ids task_ids ON task_ids.id = sts.task_id
WHERE s.last_subscribed_at < ? AND s.status = ? AND s.id >= ? AND s.id < ?",
[$threshold_date_iso, Subscriber::STATUS_SUBSCRIBED, $start_id, $end_id]
[$thresholdDateIso, Subscriber::STATUS_SUBSCRIBED, $startId, $endId]
);
$ids_to_deactivate = ORM::forTable($inactive_subscriber_ids_tmp_table)->rawQuery("
$idsToDeactivate = ORM::forTable($inactiveSubscriberIdsTmpTable)->rawQuery("
SELECT s.id FROM $inactive_subscriber_ids_tmp_table s
LEFT OUTER JOIN $statistics_opens_table as so ON s.id = so.subscriber_id AND so.created_at > ?
WHERE so.id IS NULL",
[$threshold_date_iso]
[$thresholdDateIso]
)->findArray();
ORM::rawExecute("DROP TABLE $inactive_subscriber_ids_tmp_table");
$ids_to_deactivate = array_map(
$idsToDeactivate = array_map(
function ($id) {
return (int)$id['id'];
},
$ids_to_deactivate
$idsToDeactivate
);
if (!count($ids_to_deactivate)) {
if (!count($idsToDeactivate)) {
return 0;
}
ORM::rawExecute(sprintf(
"UPDATE %s SET status='" . Subscriber::STATUS_INACTIVE . "' WHERE id IN (%s);",
$subscribers_table,
implode(',', $ids_to_deactivate)
$subscribersTable,
implode(',', $idsToDeactivate)
));
return count($ids_to_deactivate);
return count($idsToDeactivate);
}
/**
@@ -153,47 +153,47 @@ class InactiveSubscribersController {
* @param int $batch_size
* @return int
*/
private function activateSubscribers(Carbon $threshold_date, $batch_size) {
$subscribers_table = Subscriber::$_table;
$stats_opens_table = StatisticsOpens::$_table;
private function activateSubscribers(Carbon $thresholdDate, $batchSize) {
$subscribersTable = Subscriber::$_table;
$statsOpensTable = StatisticsOpens::$_table;
$mp2_migration_date = $this->getMP2MigrationDate();
if ($mp2_migration_date && $mp2_migration_date > $threshold_date) {
$mp2MigrationDate = $this->getMP2MigrationDate();
if ($mp2MigrationDate && $mp2MigrationDate > $thresholdDate) {
// If MP2 migration occurred during detection interval re-activate all subscribers created before migration
$ids_to_activate = ORM::forTable($subscribers_table)->select("$subscribers_table.id")
->whereLt("$subscribers_table.created_at", $mp2_migration_date)
$idsToActivate = ORM::forTable($subscribersTable)->select("$subscribers_table.id")
->whereLt("$subscribers_table.created_at", $mp2MigrationDate)
->where("$subscribers_table.status", Subscriber::STATUS_INACTIVE)
->limit($batch_size)
->limit($batchSize)
->findArray();
} else {
$ids_to_activate = ORM::forTable($subscribers_table)->select("$subscribers_table.id")
->leftOuterJoin($stats_opens_table, "$subscribers_table.id = $stats_opens_table.subscriber_id AND $stats_opens_table.created_at > '$threshold_date'")
->whereLt("$subscribers_table.last_subscribed_at", $threshold_date)
$idsToActivate = ORM::forTable($subscribersTable)->select("$subscribers_table.id")
->leftOuterJoin($statsOpensTable, "$subscribers_table.id = $stats_opens_table.subscriber_id AND $stats_opens_table.created_at > '$threshold_date'")
->whereLt("$subscribers_table.last_subscribed_at", $thresholdDate)
->where("$subscribers_table.status", Subscriber::STATUS_INACTIVE)
->whereRaw("$stats_opens_table.id IS NOT NULL")
->limit($batch_size)
->limit($batchSize)
->groupByExpr("$subscribers_table.id")
->findArray();
}
$ids_to_activate = array_map(
$idsToActivate = array_map(
function($id) {
return (int)$id['id'];
}, $ids_to_activate
}, $idsToActivate
);
if (!count($ids_to_activate)) {
if (!count($idsToActivate)) {
return 0;
}
ORM::rawExecute(sprintf(
"UPDATE %s SET status='" . Subscriber::STATUS_SUBSCRIBED . "' WHERE id IN (%s);",
$subscribers_table,
implode(',', $ids_to_activate)
$subscribersTable,
implode(',', $idsToActivate)
));
return count($ids_to_activate);
return count($idsToActivate);
}
private function getMP2MigrationDate() {
$setting = $this->settings_repository->findOneByName(MP2Migrator::MIGRATION_COMPLETE_SETTING_KEY);
$setting = $this->settingsRepository->findOneByName(MP2Migrator::MIGRATION_COMPLETE_SETTING_KEY);
return $setting ? Carbon::instance($setting->getCreatedAt()) : null;
}
}