Update code for PHP 5.5
[MAILPOET-1496]
This commit is contained in:
@ -288,7 +288,7 @@ class RoboFile extends \Robo\Tasks {
|
|||||||
->taskExec(
|
->taskExec(
|
||||||
'./vendor/bin/phpcs '.
|
'./vendor/bin/phpcs '.
|
||||||
'--standard=./tasks/code_sniffer/MailPoet '.
|
'--standard=./tasks/code_sniffer/MailPoet '.
|
||||||
'--runtime-set testVersion 5.4-7.2 '.
|
'--runtime-set testVersion 5.5-7.2 '.
|
||||||
'--ignore=./lib/Util/Sudzy/*,./lib/Util/CSS.php,./lib/Util/XLSXWriter.php,'.
|
'--ignore=./lib/Util/Sudzy/*,./lib/Util/CSS.php,./lib/Util/XLSXWriter.php,'.
|
||||||
'./lib/Util/pQuery/*,./lib/Config/PopulatorData/Templates/* '.
|
'./lib/Util/pQuery/*,./lib/Config/PopulatorData/Templates/* '.
|
||||||
'lib/ '.
|
'lib/ '.
|
||||||
@ -297,7 +297,7 @@ class RoboFile extends \Robo\Tasks {
|
|||||||
->taskExec(
|
->taskExec(
|
||||||
'./vendor/bin/phpcs '.
|
'./vendor/bin/phpcs '.
|
||||||
'--standard=./tasks/code_sniffer/MailPoet '.
|
'--standard=./tasks/code_sniffer/MailPoet '.
|
||||||
'--runtime-set testVersion 5.4-7.2 '.
|
'--runtime-set testVersion 5.5-7.2 '.
|
||||||
'--ignore=./tests/unit/_bootstrap.php '.
|
'--ignore=./tests/unit/_bootstrap.php '.
|
||||||
'tests/unit/ '.
|
'tests/unit/ '.
|
||||||
$severityFlag
|
$severityFlag
|
||||||
|
@ -10,7 +10,7 @@
|
|||||||
}
|
}
|
||||||
],
|
],
|
||||||
"require": {
|
"require": {
|
||||||
"php": ">=5.4",
|
"php": ">=5.5",
|
||||||
"twig/twig": "1.*",
|
"twig/twig": "1.*",
|
||||||
"cerdic/css-tidy": "^1.5.5",
|
"cerdic/css-tidy": "^1.5.5",
|
||||||
"tburry/pquery": "^1.1.1",
|
"tburry/pquery": "^1.1.1",
|
||||||
|
@ -65,7 +65,7 @@ class Bounce extends SimpleWorker {
|
|||||||
->whereIn('id', $subscribers_to_process_ids)
|
->whereIn('id', $subscribers_to_process_ids)
|
||||||
->whereNull('deleted_at')
|
->whereNull('deleted_at')
|
||||||
->findArray();
|
->findArray();
|
||||||
$subscriber_emails = Helpers::arrayColumn($subscriber_emails, 'email');
|
$subscriber_emails = array_column($subscriber_emails, 'email');
|
||||||
|
|
||||||
$this->processEmails($subscriber_emails);
|
$this->processEmails($subscriber_emails);
|
||||||
|
|
||||||
|
@ -460,7 +460,7 @@ class Newsletter extends Model {
|
|||||||
|
|
||||||
function withDeletedSegments() {
|
function withDeletedSegments() {
|
||||||
if(!empty($this->segments)) {
|
if(!empty($this->segments)) {
|
||||||
$segment_ids = Helpers::arrayColumn($this->segments, 'id');
|
$segment_ids = array_column($this->segments, 'id');
|
||||||
$links = $this->segmentRelations()
|
$links = $this->segmentRelations()
|
||||||
->whereNotIn('segment_id', $segment_ids)->findArray();
|
->whereNotIn('segment_id', $segment_ids)->findArray();
|
||||||
$deleted_segments = array();
|
$deleted_segments = array();
|
||||||
@ -501,7 +501,7 @@ class Newsletter extends Model {
|
|||||||
if(empty($options)) {
|
if(empty($options)) {
|
||||||
$this->options = array();
|
$this->options = array();
|
||||||
} else {
|
} else {
|
||||||
$this->options = Helpers::arrayColumn($options, 'value', 'name');
|
$this->options = array_column($options, 'value', 'name');
|
||||||
}
|
}
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
@ -532,7 +532,7 @@ class Subscriber extends Model {
|
|||||||
$custom_fields = CustomField::select('id')->findArray();
|
$custom_fields = CustomField::select('id')->findArray();
|
||||||
if(empty($custom_fields)) return $this;
|
if(empty($custom_fields)) return $this;
|
||||||
|
|
||||||
$custom_field_ids = Helpers::arrayColumn($custom_fields, 'id');
|
$custom_field_ids = array_column($custom_fields, 'id');
|
||||||
$relations = SubscriberCustomField::select('custom_field_id')
|
$relations = SubscriberCustomField::select('custom_field_id')
|
||||||
->select('value')
|
->select('value')
|
||||||
->whereIn('custom_field_id', $custom_field_ids)
|
->whereIn('custom_field_id', $custom_field_ids)
|
||||||
@ -845,7 +845,7 @@ class Subscriber extends Model {
|
|||||||
'(' . rtrim(str_repeat('?,', count($subscribers)), ',') . ')',
|
'(' . rtrim(str_repeat('?,', count($subscribers)), ',') . ')',
|
||||||
array_merge(
|
array_merge(
|
||||||
Helpers::flattenArray($sql('values')),
|
Helpers::flattenArray($sql('values')),
|
||||||
Helpers::arrayColumn($subscribers, $email_position)
|
array_column($subscribers, $email_position)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -83,7 +83,7 @@ class SubscribersFinder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private function addSubscribersToTaskFromStaticSegments(ScheduledTask $task, array $segments) {
|
private function addSubscribersToTaskFromStaticSegments(ScheduledTask $task, array $segments) {
|
||||||
$segment_ids = Helpers::arrayColumn($segments, 'id');
|
$segment_ids = array_column($segments, 'id');
|
||||||
Subscriber::rawExecute(
|
Subscriber::rawExecute(
|
||||||
'INSERT IGNORE INTO ' . MP_SCHEDULED_TASK_SUBSCRIBERS_TABLE . '
|
'INSERT IGNORE INTO ' . MP_SCHEDULED_TASK_SUBSCRIBERS_TABLE . '
|
||||||
(task_id, subscriber_id, processed)
|
(task_id, subscriber_id, processed)
|
||||||
@ -125,7 +125,7 @@ class SubscribersFinder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private function addSubscribersToTaskByIds(ScheduledTask $task, array $subscribers) {
|
private function addSubscribersToTaskByIds(ScheduledTask $task, array $subscribers) {
|
||||||
$subscribers = Helpers::arrayColumn($subscribers, 'id');
|
$subscribers = array_column($subscribers, 'id');
|
||||||
Subscriber::rawExecute(
|
Subscriber::rawExecute(
|
||||||
'INSERT IGNORE INTO ' . MP_SCHEDULED_TASK_SUBSCRIBERS_TABLE . '
|
'INSERT IGNORE INTO ' . MP_SCHEDULED_TASK_SUBSCRIBERS_TABLE . '
|
||||||
(task_id, subscriber_id, processed)
|
(task_id, subscriber_id, processed)
|
||||||
|
@ -192,7 +192,7 @@ class Export {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function getSubscriberCustomFields() {
|
function getSubscriberCustomFields() {
|
||||||
return Helpers::arrayColumn(
|
return array_column(
|
||||||
CustomField::findArray(),
|
CustomField::findArray(),
|
||||||
'name',
|
'name',
|
||||||
'id'
|
'id'
|
||||||
|
@ -194,7 +194,7 @@ class Import {
|
|||||||
|
|
||||||
function transformSubscribersData($subscribers, $columns) {
|
function transformSubscribersData($subscribers, $columns) {
|
||||||
foreach($columns as $column => $data) {
|
foreach($columns as $column => $data) {
|
||||||
$transformed_subscribers[$column] = Helpers::arrayColumn($subscribers, $data['index']);
|
$transformed_subscribers[$column] = array_column($subscribers, $data['index']);
|
||||||
}
|
}
|
||||||
return $transformed_subscribers;
|
return $transformed_subscribers;
|
||||||
}
|
}
|
||||||
@ -223,7 +223,7 @@ class Import {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
// extract WP users ids into a simple indexed array: [wp_user_id_1, wp_user_id_2, ...]
|
// extract WP users ids into a simple indexed array: [wp_user_id_1, wp_user_id_2, ...]
|
||||||
$wp_users = array_filter(Helpers::arrayColumn($temp_existing_subscribers, 'wp_user_id'));
|
$wp_users = array_filter(array_column($temp_existing_subscribers, 'wp_user_id'));
|
||||||
// create a new two-dimensional associative array with existing subscribers ($existing_subscribers)
|
// create a new two-dimensional associative array with existing subscribers ($existing_subscribers)
|
||||||
// and reduce $subscribers_data to only new subscribers by removing existing subscribers
|
// and reduce $subscribers_data to only new subscribers by removing existing subscribers
|
||||||
$subscribers_emails = array_flip($subscribers_data['email']);
|
$subscribers_emails = array_flip($subscribers_data['email']);
|
||||||
@ -353,7 +353,7 @@ class Import {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
if(empty($created_or_updated_subscribers)) return null;
|
if(empty($created_or_updated_subscribers)) return null;
|
||||||
$created_or_updated_subscribers_ids = Helpers::arrayColumn($created_or_updated_subscribers, 'id');
|
$created_or_updated_subscribers_ids = array_column($created_or_updated_subscribers, 'id');
|
||||||
if($subscribers_custom_fields) {
|
if($subscribers_custom_fields) {
|
||||||
$this->createOrUpdateCustomFields(
|
$this->createOrUpdateCustomFields(
|
||||||
$action,
|
$action,
|
||||||
|
@ -80,7 +80,7 @@ class Pages {
|
|||||||
if($subsciber_segments) {
|
if($subsciber_segments) {
|
||||||
Scheduler::scheduleSubscriberWelcomeNotification(
|
Scheduler::scheduleSubscriberWelcomeNotification(
|
||||||
$this->subscriber->id,
|
$this->subscriber->id,
|
||||||
Helpers::arrayColumn($subsciber_segments, 'id')
|
array_column($subsciber_segments, 'id')
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -143,7 +143,7 @@ class Sending {
|
|||||||
$subscribers->where('processed', $status);
|
$subscribers->where('processed', $status);
|
||||||
}
|
}
|
||||||
$subscribers = $subscribers->findArray();
|
$subscribers = $subscribers->findArray();
|
||||||
return Helpers::arrayColumn($subscribers, 'subscriber_id');
|
return array_column($subscribers, 'subscriber_id');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setSubscribers(array $subscriber_ids) {
|
public function setSubscribers(array $subscriber_ids) {
|
||||||
|
@ -31,7 +31,7 @@ class BatchIterator implements \Iterator, \Countable {
|
|||||||
->orderByAsc('subscriber_id')
|
->orderByAsc('subscriber_id')
|
||||||
->limit($this->batch_size)
|
->limit($this->batch_size)
|
||||||
->findArray();
|
->findArray();
|
||||||
$subscribers = Helpers::arrayColumn($subscribers, 'subscriber_id');
|
$subscribers = array_column($subscribers, 'subscriber_id');
|
||||||
$this->batch_last_id = end($subscribers);
|
$this->batch_last_id = end($subscribers);
|
||||||
return $subscribers;
|
return $subscribers;
|
||||||
}
|
}
|
||||||
|
@ -57,79 +57,6 @@ class Helpers {
|
|||||||
return $flattened_array;
|
return $flattened_array;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* Using func_get_args() in order to check for proper number ofparameters and trigger errors exactly as the built-in array_column()
|
|
||||||
* does in PHP 5.5.
|
|
||||||
* @author Ben Ramsey (http://benramsey.com)
|
|
||||||
*/
|
|
||||||
static function arrayColumn($input = null, $columnKey = null, $indexKey = null) {
|
|
||||||
$argc = func_num_args();
|
|
||||||
$params = func_get_args();
|
|
||||||
if($argc < 2) {
|
|
||||||
trigger_error("array_column() expects at least 2 parameters, {$argc} given", E_USER_WARNING);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
if(!is_array($params[0])) {
|
|
||||||
trigger_error(
|
|
||||||
'array_column() expects parameter 1 to be array, ' . gettype($params[0]) . ' given',
|
|
||||||
E_USER_WARNING
|
|
||||||
);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
if(!is_int($params[1])
|
|
||||||
&& !is_float($params[1])
|
|
||||||
&& !is_string($params[1])
|
|
||||||
&& $params[1] !== null
|
|
||||||
&& !(is_object($params[1]) && method_exists($params[1], '__toString'))
|
|
||||||
) {
|
|
||||||
trigger_error('array_column(): The column key should be either a string or an integer', E_USER_WARNING);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if(isset($params[2])
|
|
||||||
&& !is_int($params[2])
|
|
||||||
&& !is_float($params[2])
|
|
||||||
&& !is_string($params[2])
|
|
||||||
&& !(is_object($params[2]) && method_exists($params[2], '__toString'))
|
|
||||||
) {
|
|
||||||
trigger_error('array_column(): The index key should be either a string or an integer', E_USER_WARNING);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
$paramsInput = $params[0];
|
|
||||||
$paramsColumnKey = ($params[1] !== null) ? (string)$params[1] : null;
|
|
||||||
$paramsIndexKey = null;
|
|
||||||
if(isset($params[2])) {
|
|
||||||
if(is_float($params[2]) || is_int($params[2])) {
|
|
||||||
$paramsIndexKey = (int)$params[2];
|
|
||||||
} else {
|
|
||||||
$paramsIndexKey = (string)$params[2];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$resultArray = array();
|
|
||||||
foreach($paramsInput as $row) {
|
|
||||||
$key = $value = null;
|
|
||||||
$keySet = $valueSet = false;
|
|
||||||
if($paramsIndexKey !== null && array_key_exists($paramsIndexKey, $row)) {
|
|
||||||
$keySet = true;
|
|
||||||
$key = (string)$row[$paramsIndexKey];
|
|
||||||
}
|
|
||||||
if($paramsColumnKey === null) {
|
|
||||||
$valueSet = true;
|
|
||||||
$value = $row;
|
|
||||||
} elseif(is_array($row) && array_key_exists($paramsColumnKey, $row)) {
|
|
||||||
$valueSet = true;
|
|
||||||
$value = $row[$paramsColumnKey];
|
|
||||||
}
|
|
||||||
if($valueSet) {
|
|
||||||
if($keySet) {
|
|
||||||
$resultArray[$key] = $value;
|
|
||||||
} else {
|
|
||||||
$resultArray[] = $value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return $resultArray;
|
|
||||||
}
|
|
||||||
|
|
||||||
static function underscoreToCamelCase($str, $capitalise_first_char = false) {
|
static function underscoreToCamelCase($str, $capitalise_first_char = false) {
|
||||||
if($capitalise_first_char) {
|
if($capitalise_first_char) {
|
||||||
$str[0] = strtoupper($str[0]);
|
$str[0] = strtoupper($str[0]);
|
||||||
|
@ -86,7 +86,7 @@ class BounceTest extends \MailPoetTest {
|
|||||||
|
|
||||||
function testItSetsSubscriberStatusAsBounced() {
|
function testItSetsSubscriberStatusAsBounced() {
|
||||||
$emails = Subscriber::select('email')->findArray();
|
$emails = Subscriber::select('email')->findArray();
|
||||||
$emails = Helpers::arrayColumn($emails, 'email');
|
$emails = array_column($emails, 'email');
|
||||||
|
|
||||||
$this->worker->processEmails($emails);
|
$this->worker->processEmails($emails);
|
||||||
|
|
||||||
|
@ -289,7 +289,7 @@ class ImportTest extends \MailPoetTest {
|
|||||||
'create',
|
'create',
|
||||||
$subscribers_data
|
$subscribers_data
|
||||||
);
|
);
|
||||||
$db_subscribers = Helpers::arrayColumn(
|
$db_subscribers = array_column(
|
||||||
Subscriber::select('id')
|
Subscriber::select('id')
|
||||||
->findArray(),
|
->findArray(),
|
||||||
'id'
|
'id'
|
||||||
@ -354,7 +354,7 @@ class ImportTest extends \MailPoetTest {
|
|||||||
$subscribers_data,
|
$subscribers_data,
|
||||||
$this->subscribers_fields
|
$this->subscribers_fields
|
||||||
);
|
);
|
||||||
$db_subscribers = Helpers::arrayColumn(
|
$db_subscribers = array_column(
|
||||||
Subscriber::select('id')
|
Subscriber::select('id')
|
||||||
->findArray(),
|
->findArray(),
|
||||||
'id'
|
'id'
|
||||||
@ -467,7 +467,7 @@ class ImportTest extends \MailPoetTest {
|
|||||||
$this->import->updated_at = date('Y-m-d H:i:s', $timestamp + 1);
|
$this->import->updated_at = date('Y-m-d H:i:s', $timestamp + 1);
|
||||||
$result = $this->import->process();
|
$result = $this->import->process();
|
||||||
expect($result['created'])->equals(1);
|
expect($result['created'])->equals(1);
|
||||||
$db_subscribers = Helpers::arrayColumn(
|
$db_subscribers = array_column(
|
||||||
Subscriber::select('id')->findArray(),
|
Subscriber::select('id')->findArray(),
|
||||||
'id'
|
'id'
|
||||||
);
|
);
|
||||||
|
Reference in New Issue
Block a user