Egorka
6 years ago
20 changed files with 488 additions and 145 deletions
@ -0,0 +1,21 @@ |
|||||||
|
<?php |
||||||
|
/** |
||||||
|
* Created by Error202 |
||||||
|
* Date: 27.07.2018 |
||||||
|
*/ |
||||||
|
|
||||||
|
namespace common\modules\pages\entities\queries; |
||||||
|
|
||||||
|
|
||||||
|
use common\modules\pages\entities\Page; |
||||||
|
use yii\db\ActiveQuery; |
||||||
|
|
||||||
|
class PageQuery extends ActiveQuery |
||||||
|
{ |
||||||
|
public function typePublic($alias = null) |
||||||
|
{ |
||||||
|
return $this->andWhere([ |
||||||
|
($alias ? $alias . '.' : '') . 'type' => Page::TYPE_PUBLIC, |
||||||
|
]); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,40 @@ |
|||||||
|
<?php |
||||||
|
/** |
||||||
|
* Created by Error202 |
||||||
|
* Date: 27.07.2018 |
||||||
|
*/ |
||||||
|
|
||||||
|
namespace common\modules\pages\helpers; |
||||||
|
|
||||||
|
use common\modules\pages\entities\Page; |
||||||
|
use core\entities\Meta; |
||||||
|
|
||||||
|
class PageHelper |
||||||
|
{ |
||||||
|
public static function saveRevision(Page $model) { |
||||||
|
if (!$model->revision_id) { |
||||||
|
|
||||||
|
$model->revision_at = time(); |
||||||
|
|
||||||
|
$page = Page::create( |
||||||
|
$model->title, |
||||||
|
$model->slug, |
||||||
|
$model->content, |
||||||
|
new Meta( |
||||||
|
$model->meta->title, |
||||||
|
$model->meta->description, |
||||||
|
$model->meta->keywords |
||||||
|
) |
||||||
|
); |
||||||
|
|
||||||
|
$page->revision_at = $model->updated_at; |
||||||
|
$page->revision_id = $model->id; |
||||||
|
$page->type = Page::TYPE_REVISION; |
||||||
|
//$page->tree = 2; |
||||||
|
|
||||||
|
$parent = Page::find()->andWhere(['slug' => 'temp'])->andWhere(['depth' => 0])->one(); |
||||||
|
$page->appendTo($parent); |
||||||
|
$page->save(); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,35 @@ |
|||||||
|
<?php |
||||||
|
|
||||||
|
use yii\db\Migration; |
||||||
|
|
||||||
|
/** |
||||||
|
* Class m180727_110133_add_pages_revision_fields |
||||||
|
*/ |
||||||
|
class m180727_110133_add_pages_revision_fields extends Migration |
||||||
|
{ |
||||||
|
/** |
||||||
|
* {@inheritdoc} |
||||||
|
*/ |
||||||
|
public function safeUp() |
||||||
|
{ |
||||||
|
$this->addColumn('{{%pages}}', 'type', $this->integer(2)->defaultValue(0)); // 0 - public, 1 - revision, 2 - preview |
||||||
|
$this->addColumn('{{%pages}}', 'revision_at', $this->integer()->unsigned()); |
||||||
|
$this->addColumn('{{%pages}}', 'revision_id', $this->integer()); |
||||||
|
|
||||||
|
$this->dropIndex('{{%idx-pages-slug}}', '{{%pages}}'); |
||||||
|
$this->createIndex('{{%idx-pages-slug}}', '{{%pages}}', 'slug'); |
||||||
|
|
||||||
|
$this->createIndex('idx_pages_revision_id', '{{%pages}}', 'revision_id'); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* {@inheritdoc} |
||||||
|
*/ |
||||||
|
public function safeDown() |
||||||
|
{ |
||||||
|
$this->dropIndex('idx_pages_revision_id', '{{%pages}}'); |
||||||
|
$this->dropColumn('{{%pages}}', 'type'); |
||||||
|
$this->dropColumn('{{%pages}}', 'revision_at'); |
||||||
|
$this->dropColumn('{{%pages}}', 'revision_id'); |
||||||
|
} |
||||||
|
} |
Loading…
Reference in new issue