Skip to content

Commit

Permalink
Merge pull request #34 from UseMuffin/next
Browse files Browse the repository at this point in the history
Next
  • Loading branch information
ADmad authored Apr 17, 2018
2 parents 14ba3b8 + f9fc464 commit a995ce3
Show file tree
Hide file tree
Showing 4 changed files with 112 additions and 93 deletions.
27 changes: 14 additions & 13 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
language: php

php:
- 5.4
- 5.5
- 5.6
- 7.0
- 7.1

sudo: false
- 7.2

env:
matrix:
Expand All @@ -22,17 +19,22 @@ matrix:
fast_finish: true

include:
- php: 7.0
- php: 7.1
env: PHPCS=1 DEFAULT=0

- php: 7.0
- php: 7.1
env: PHPSTAN=1 DEFAULT=0

- php: 5.6
env: PREFER_LOWEST=1

before_script:
- if [[ $TRAVIS_PHP_VERSION != 7.0 ]]; then phpenv config-rm xdebug.ini; fi
- if [[ $TRAVIS_PHP_VERSION != 7.1 ]]; then phpenv config-rm xdebug.ini; fi

- composer self-update
- composer install --prefer-dist --no-interaction
- if [[ $PREFER_LOWEST != 1 ]]; then composer update --no-interaction ; fi
- if [[ $PREFER_LOWEST == 1 ]]; then composer update --no-interaction --prefer-lowest --prefer-stable; fi

- if [[ $PHPSTAN = 1 ]]; then composer require phpstan/phpstan; fi

- if [[ $DB = 'mysql' ]]; then mysql -e 'CREATE DATABASE cakephp_test;'; fi
- if [[ $DB = 'pgsql' ]]; then psql -c 'CREATE DATABASE cakephp_test;' -U postgres; fi
Expand All @@ -41,15 +43,14 @@ before_script:
- if [[ $PHPSTAN = 1 ]]; then composer require phpstan/phpstan; fi

script:
- if [[ $DEFAULT = 1 && $TRAVIS_PHP_VERSION != 7.0 ]]; then vendor/bin/phpunit; fi
- if [[ $DEFAULT = 1 && $TRAVIS_PHP_VERSION = 7.0 ]]; then vendor/bin/phpunit --coverage-clover=clover.xml; fi
- if [[ $DEFAULT = 1 && $TRAVIS_PHP_VERSION != 7.1 ]]; then vendor/bin/phpunit; fi
- if [[ $DEFAULT = 1 && $TRAVIS_PHP_VERSION = 7.1 ]]; then vendor/bin/phpunit --coverage-clover=clover.xml; fi

- if [[ $PHPCS = 1 ]]; then vendor/bin/phpcs -n -p --extensions=php --standard=vendor/cakephp/cakephp-codesniffer/CakePHP ./src ./tests; fi

- if [[ $PHPSTAN = 1 ]]; then vendor/bin/phpstan analyse -c phpstan.neon -l 5 src; fi

after_success:
- if [[ $DEFAULT = 1 && $TRAVIS_PHP_VERSION = 7.0 ]]; then bash <(curl -s https://codecov.io/bash); fi
- if [[ $DEFAULT = 1 && $TRAVIS_PHP_VERSION = 7.1 ]]; then bash <(curl -s https://codecov.io/bash); fi

notifications:
email: false
7 changes: 4 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,12 @@
"source": "https://github.com/usemuffin/trash"
},
"require": {
"cakephp/orm": "^3.0"
"cakephp/orm": "^3.5"
},
"require-dev": {
"phpunit/phpunit": "<6.0",
"cakephp/cakephp": "^3.0"
"cakephp/chronos": "^1.1",
"cakephp/cakephp": "^3.5",
"phpunit/phpunit": "^5.7.14|^6.0"
},
"autoload": {
"psr-4": {
Expand Down
40 changes: 21 additions & 19 deletions src/Model/Behavior/TrashBehavior.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class TrashBehavior extends Behavior
public function initialize(array $config)
{
if (!empty($config['events'])) {
$this->config('events', $config['events'], false);
$this->setConfig('events', $config['events'], false);
}
}

Expand All @@ -61,10 +61,10 @@ public function initialize(array $config)
public function implementedEvents()
{
$events = [];
if ($this->config('events') === false) {
if ($this->getConfig('events') === false) {
return $events;
}
foreach ((array)$this->config('events') as $eventKey => $event) {
foreach ((array)$this->getConfig('events') as $eventKey => $event) {
if (is_numeric($eventKey)) {
$eventKey = $event;
$event = null;
Expand All @@ -75,7 +75,7 @@ public function implementedEvents()
if (!is_array($event)) {
throw new \InvalidArgumentException('Event should be string or array');
}
$priority = $this->config('priority');
$priority = $this->getConfig('priority');
if (!array_key_exists('callable', $event) || $event['callable'] === null) {
list(, $event['callable']) = pluginSplit($eventKey);
}
Expand Down Expand Up @@ -106,7 +106,7 @@ public function beforeDelete(Event $event, EntityInterface $entity, ArrayObject
$event->stopPropagation();

/** @var \Cake\ORM\Table $table */
$table = $event->subject();
$table = $event->getSubject();
$table->dispatchEvent('Model.afterDelete', [
'entity' => $entity,
'options' => $options,
Expand All @@ -125,10 +125,12 @@ public function beforeDelete(Event $event, EntityInterface $entity, ArrayObject
*/
public function trash(EntityInterface $entity, array $options = [])
{
$primaryKey = (array)$this->_table->primaryKey();
$primaryKey = (array)$this->_table->getPrimaryKey();

if (!$entity->has($primaryKey)) {
throw new RuntimeException();
foreach ($primaryKey as $field) {
if (!$entity->has($field)) {
throw new RuntimeException();
}
}

foreach ($this->_table->associations() as $association) {
Expand Down Expand Up @@ -241,7 +243,7 @@ public function restoreTrash(EntityInterface $entity = null, array $options = []
$data = [$this->getTrashField(false) => null];

if ($entity instanceof EntityInterface) {
if ($entity->dirty()) {
if ($entity->isDirty()) {
throw new RuntimeException('Can not restore from a dirty entity.');
}
$entity->set($data, ['guard' => false]);
Expand All @@ -266,14 +268,14 @@ public function cascadingRestoreTrash(EntityInterface $entity = null, array $opt
foreach ($this->_table->associations() as $association) {
if ($this->_isRecursable($association, $this->_table)) {
if ($entity === null) {
$result += $association->target()->cascadingRestoreTrash(null, $options);
$result += $association->getTarget()->cascadingRestoreTrash(null, $options);
} else {
$foreignKey = (array)$association->foreignKey();
$bindingKey = (array)$association->bindingKey();
$foreignKey = (array)$association->getForeignKey();
$bindingKey = (array)$association->getBindingKey();
$conditions = array_combine($foreignKey, $entity->extract($bindingKey));

foreach ($association->find('withTrashed')->where($conditions) as $related) {
if (!$association->target()->cascadingRestoreTrash($related, ['_primary' => false] + $options)) {
if (!$association->getTarget()->cascadingRestoreTrash($related, ['_primary' => false] + $options)) {
$result = false;
}
}
Expand Down Expand Up @@ -306,10 +308,10 @@ protected function _getUnaryExpression()
*/
public function getTrashField($aliased = true)
{
$field = $this->config('field');
$field = $this->getConfig('field');

if (empty($field)) {
$columns = $this->_table->schema()->columns();
$columns = $this->_table->getSchema()->columns();
foreach (['deleted', 'trashed'] as $name) {
if (in_array($name, $columns, true)) {
$field = $name;
Expand All @@ -325,7 +327,7 @@ public function getTrashField($aliased = true)
throw new RuntimeException('TrashBehavior: "field" config needs to be provided.');
}

$this->config('field', $field);
$this->setConfig('field', $field);
}

if ($aliased) {
Expand All @@ -344,10 +346,10 @@ public function getTrashField($aliased = true)
*/
protected function _isRecursable(Association $association, Table $table)
{
if ($association->target()->hasBehavior('Trash')
if ($association->getTarget()->hasBehavior('Trash')
&& $association->isOwningSide($table)
&& $association->dependent()
&& $association->cascadeCallbacks()) {
&& $association->getDependent()
&& $association->getCascadeCallbacks()) {
return true;
}

Expand Down
Loading

0 comments on commit a995ce3

Please sign in to comment.