Skip to content

Commit

Permalink
Fix PHP7.3 tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
dereuromark committed Nov 29, 2018
1 parent 4314deb commit 2c85754
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
18 changes: 10 additions & 8 deletions src/Model/Behavior/ResetBehavior.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ public function resetRecords(array $params = []) {
'fields' => [],
'order' => [$this->_table->getAlias() . '.' . $this->_table->getPrimaryKey() => 'ASC'],
'conditions' => $this->_config['scope'],
'validate' => $this->_config['validate'],
];
if (!empty($this->_config['fields'])) {
foreach ((array)$this->_config['fields'] as $field) {
Expand Down Expand Up @@ -129,30 +130,31 @@ public function resetRecords(array $params = []) {
$modified = 0;
while (($records = $this->_table->find('all', $params)->toArray())) {
foreach ($records as $record) {
$fieldList = $params['fields'];
$fields = (array)$params['fields'];
if ($this->getConfig('updateFields')) {
$fieldList = $this->getConfig('updateFields');
$fields = (array)$this->getConfig('updateFields');
if (!$this->_config['updateTimestamp']) {
$fieldList = array_merge($updateFields, $fieldList);
$fields = array_merge($updateFields, $fields);
}
}
if ($fieldList && !in_array($this->_table->getPrimaryKey(), $fieldList)) {
$fieldList[] = $this->_table->getPrimaryKey();
if ($fields && !in_array($this->_table->getPrimaryKey(), $fields)) {
$fields[] = $this->_table->getPrimaryKey();
}

if ($this->_config['callback']) {
if (is_callable($this->_config['callback'])) {
$parameters = [$record, &$fieldList];
$parameters = [$record, &$fields];
$record = call_user_func_array($this->_config['callback'], $parameters);
} else {
$record = $this->_table->{$this->_config['callback']}($record, $fieldList);
$record = $this->_table->{$this->_config['callback']}($record, $fields);
}
if (!$record) {
continue;
}
}

$res = $this->_table->save($record, compact('validate', 'fieldList'));
$validate = $params['validate'];
$res = $this->_table->save($record, compact('validate', 'fields'));
if (!$res) {
throw new RuntimeException(print_r($record->getErrors(), true));
}
Expand Down
6 changes: 5 additions & 1 deletion src/Model/Behavior/SluggedBehavior.php
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,8 @@ public function resetSlugs($params = []) {
'overwrite' => true,
];
$params = array_merge($defaults, $params);

$conditions = $params['conditions'];
$count = $this->_table->find('all', compact('conditions'))->count();
$max = ini_get('max_execution_time');
if ($max) {
Expand All @@ -394,9 +396,11 @@ public function resetSlugs($params = []) {
/** @var \Cake\ORM\Entity $record */
foreach ($records as $record) {
$record->isNew(true);

$fields = array_merge([$this->_table->getPrimaryKey(), $this->_config['field']], $this->_config['label']);
$options = [
'validate' => true,
'fieldList' => array_merge([$this->_table->getPrimaryKey(), $this->_config['field']], $this->_config['label'])
'fields' => $fields,
];
if (!$this->_table->save($record, $options)) {
throw new RuntimeException(print_r($record->getErrors(), true));
Expand Down

0 comments on commit 2c85754

Please sign in to comment.