Commit a8f371b9 authored by Nicola Tomassoni's avatar Nicola Tomassoni

Digisin release

parent efa5f6bf
...@@ -11,3 +11,4 @@ vendor/ ...@@ -11,3 +11,4 @@ vendor/
# ignore temporary files # ignore temporary files
*~ *~
/nbproject/private/
\ No newline at end of file
{ {
"name": "cornernote/yii2-softdelete", "name": "digisin/yii2-softdelete",
"description": "Soft delete behavior for Yii2.", "description": "Soft delete behavior for Yii2.",
"keywords": ["yii2", "soft delete"], "keywords": ["yii2", "soft delete"],
"type": "yii2-behavior", "type": "yii2-behavior",
...@@ -8,6 +8,10 @@ ...@@ -8,6 +8,10 @@
{ {
"name": "Brett O'Donnell", "name": "Brett O'Donnell",
"email": "cornernote@gmail.com" "email": "cornernote@gmail.com"
},
{
"name": "Nicola Tomassoni",
"email": "nicola@digisin.it"
} }
], ],
"require": { "require": {
...@@ -20,7 +24,7 @@ ...@@ -20,7 +24,7 @@
}, },
"autoload": { "autoload": {
"psr-4": { "psr-4": {
"cornernote\\softdelete\\": "src" "digisin\\softdelete\\": "src"
} }
} }
} }
include.path=${php.global.include.path}
php.version=PHP_56
source.encoding=UTF-8
src.dir=.
tags.asp=false
tags.short=false
web.root=.
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://www.netbeans.org/ns/project/1">
<type>org.netbeans.modules.php.project</type>
<configuration>
<data xmlns="http://www.netbeans.org/ns/php-project/1">
<name>yii2-softdelete</name>
</data>
</configuration>
</project>
<?php <?php
/** /**
* @author Brett O'Donnell <cornernote@gmail.com> * @author Brett O'Donnell <cornernote@gmail.com>
* @copyright 2015 Mr PHP * @copyright 2015 Mr PHP
...@@ -6,7 +7,7 @@ ...@@ -6,7 +7,7 @@
* @license BSD-3-Clause https://raw.github.com/cornernote/yii2-softdelete/master/LICENSE.md * @license BSD-3-Clause https://raw.github.com/cornernote/yii2-softdelete/master/LICENSE.md
*/ */
namespace cornernote\softdelete; namespace digisin\softdelete;
use yii\base\Behavior; use yii\base\Behavior;
use yii\base\Event; use yii\base\Event;
...@@ -31,8 +32,8 @@ use yii\db\Expression; ...@@ -31,8 +32,8 @@ use yii\db\Expression;
* *
* @property BaseActiveRecord $owner * @property BaseActiveRecord $owner
*/ */
class SoftDeleteBehavior extends Behavior class SoftDeleteBehavior extends Behavior {
{
/** /**
* @var string SoftDelete attribute * @var string SoftDelete attribute
*/ */
...@@ -49,8 +50,7 @@ class SoftDeleteBehavior extends Behavior ...@@ -49,8 +50,7 @@ class SoftDeleteBehavior extends Behavior
/** /**
* @inheritdoc * @inheritdoc
*/ */
public function events() public function events() {
{
return [BaseActiveRecord::EVENT_BEFORE_DELETE => 'softDeleteEvent']; return [BaseActiveRecord::EVENT_BEFORE_DELETE => 'softDeleteEvent'];
} }
...@@ -59,8 +59,7 @@ class SoftDeleteBehavior extends Behavior ...@@ -59,8 +59,7 @@ class SoftDeleteBehavior extends Behavior
* *
* @param Event $event * @param Event $event
*/ */
public function softDeleteEvent($event) public function softDeleteEvent($event) {
{
// remove and mark as invalid to prevent real deletion // remove and mark as invalid to prevent real deletion
$this->softDelete(); $this->softDelete();
$event->isValid = false; $event->isValid = false;
...@@ -69,8 +68,7 @@ class SoftDeleteBehavior extends Behavior ...@@ -69,8 +68,7 @@ class SoftDeleteBehavior extends Behavior
/** /**
* Soft delete record * Soft delete record
*/ */
public function softDelete() public function softDelete() {
{
// set attribute with evaluated timestamp // set attribute with evaluated timestamp
$attribute = $this->attribute; $attribute = $this->attribute;
$this->owner->$attribute = $this->getValue(null); $this->owner->$attribute = $this->getValue(null);
...@@ -81,8 +79,7 @@ class SoftDeleteBehavior extends Behavior ...@@ -81,8 +79,7 @@ class SoftDeleteBehavior extends Behavior
/** /**
* Restore record * Restore record
*/ */
public function unDelete() public function unDelete() {
{
// set attribute as null // set attribute as null
$attribute = $this->attribute; $attribute = $this->attribute;
$this->owner->$attribute = null; $this->owner->$attribute = null;
...@@ -93,8 +90,7 @@ class SoftDeleteBehavior extends Behavior ...@@ -93,8 +90,7 @@ class SoftDeleteBehavior extends Behavior
/** /**
* Delete record from database regardless of the $safeMode attribute * Delete record from database regardless of the $safeMode attribute
*/ */
public function hardDelete() public function hardDelete() {
{
// store model so that we can detach the behavior // store model so that we can detach the behavior
$model = $this->owner; $model = $this->owner;
$this->detach(); $this->detach();
...@@ -108,8 +104,7 @@ class SoftDeleteBehavior extends Behavior ...@@ -108,8 +104,7 @@ class SoftDeleteBehavior extends Behavior
* @param Event|null $event the event that triggers the current attribute updating. * @param Event|null $event the event that triggers the current attribute updating.
* @return mixed the attribute value * @return mixed the attribute value
*/ */
protected function getValue($event) protected function getValue($event) {
{
if ($this->value instanceof Expression) { if ($this->value instanceof Expression) {
return $this->value; return $this->value;
} else { } else {
......
<?php <?php
namespace cornernote\softdelete; namespace digisin\softdelete;
use yii\base\Behavior; use yii\base\Behavior;
use yii\db\ActiveQuery; use yii\db\ActiveQuery;
...@@ -25,8 +25,8 @@ use yii\db\ActiveRecord; ...@@ -25,8 +25,8 @@ use yii\db\ActiveRecord;
* *
* @author cornernote <cornernote@gmail.com> * @author cornernote <cornernote@gmail.com>
*/ */
class SoftDeleteQueryBehavior extends Behavior class SoftDeleteQueryBehavior extends Behavior {
{
/** /**
* @var string SoftDelete attribute * @var string SoftDelete attribute
*/ */
...@@ -35,24 +35,21 @@ class SoftDeleteQueryBehavior extends Behavior ...@@ -35,24 +35,21 @@ class SoftDeleteQueryBehavior extends Behavior
/** /**
* @return static * @return static
*/ */
public function deleted() public function deleted() {
{
return $this->owner->andWhere($this->tableName() . '.' . $this->attribute . ' IS NOT NULL'); return $this->owner->andWhere($this->tableName() . '.' . $this->attribute . ' IS NOT NULL');
} }
/** /**
* @return static * @return static
*/ */
public function notDeleted() public function notDeleted() {
{
return $this->owner->andWhere($this->tableName() . '.' . $this->attribute . ' IS NULL'); return $this->owner->andWhere($this->tableName() . '.' . $this->attribute . ' IS NULL');
} }
/** /**
* @return string * @return string
*/ */
protected function tableName() protected function tableName() {
{
/** @var ActiveRecord $modelClass */ /** @var ActiveRecord $modelClass */
$modelClass = $this->owner->modelClass; $modelClass = $this->owner->modelClass;
return $modelClass::tableName(); return $modelClass::tableName();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment