Skip to content
This repository has been archived by the owner on Jan 25, 2021. It is now read-only.

Let's pass the old Page and File objects to some hooks #833

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 5 additions & 2 deletions app/src/panel/models/file.php
Expand Up @@ -114,9 +114,12 @@ public function rename($name, $safeName = true) {

public function update($data = array(), $sort = null) {

// keep the old state of the file object
$old = clone $this;

if($data == 'sort') {
parent::update(array('sort' => $sort));
kirby()->trigger('panel.file.sort', $this);
kirby()->trigger('panel.file.sort', array($this, $old));
return true;
}

Expand All @@ -134,7 +137,7 @@ public function update($data = array(), $sort = null) {
parent::update($data);
}

kirby()->trigger('panel.file.update', $this);
kirby()->trigger('panel.file.update', array($this, $old));

}

Expand Down
23 changes: 15 additions & 8 deletions app/src/panel/models/page.php
Expand Up @@ -284,7 +284,8 @@ public function canChangeTemplate() {

public function move($uid) {

$old = clone($this);
// keep the old state of the page object
$old = clone $this;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I only edited this to be consistent.


if(!$this->canChangeUrl()) {
throw new Exception(l('pages.url.error.rights'));
Expand Down Expand Up @@ -323,6 +324,9 @@ public function _sort($to) {

public function sort($to = null) {

// keep the old state of the page object
$old = clone $this;

if($this->isErrorPage()) {
return $this->num();
}
Expand All @@ -332,16 +336,13 @@ public function sort($to = null) {
return false;
}

// store the old number
$oldNum = $this->num();

// run the sorter
$this->sorter()->to($to);

// run the hook if the number changed
if($oldNum != $this->num()) {
if($old->num() != $this->num()) {
// hit the hook
kirby()->trigger('panel.page.sort', $this);
kirby()->trigger('panel.page.sort', array($this, $old));
}

return $this->num();
Expand All @@ -359,9 +360,12 @@ public function hide() {
return false;
}

// keep the old state of the page object
$old = clone $this;

parent::hide();
$this->sorter()->hide();
kirby()->trigger('panel.page.hide', $this);
kirby()->trigger('panel.page.hide', array($this, $old));

}

Expand Down Expand Up @@ -441,6 +445,9 @@ public function updateUid() {

public function update($data = array(), $lang = null) {

// keep the old state of the page object
$old = clone $this;

$this->changes()->discard();

parent::update($data, $lang);
Expand All @@ -449,7 +456,7 @@ public function update($data = array(), $lang = null) {
// changed for example
$this->updateNum();

kirby()->trigger('panel.page.update', $this);
kirby()->trigger('panel.page.update', array($this, $old));

// add the page to the history
$this->addToHistory();
Expand Down
5 changes: 4 additions & 1 deletion app/src/panel/models/page/uploader.php
Expand Up @@ -70,6 +70,9 @@ public function upload() {

public function replace() {

// keep the old state of the file object
$old = clone $this->file;

$file = $this->file;
$upload = new Upload($file->root(), array(
'overwrite' => true,
Expand All @@ -88,7 +91,7 @@ public function replace() {
// clean the thumbs folder
$this->page->removeThumbs();

kirby()->trigger('panel.file.replace', $file);
kirby()->trigger('panel.file.replace', array($file, $old));

}

Expand Down