-
Notifications
You must be signed in to change notification settings - Fork 1
/
DbComparisonPage.class.php
162 lines (137 loc) · 4.84 KB
/
DbComparisonPage.class.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
<?php
namespace ProcessWire;
/**
* Class DbComparisonPage
*
* @package ProcessWire
*
* @property object $comparisons The parent page for comparison pages
* @property object $comparisonTemplate The template for comparison pages
* @property string $comparisonsPath Path to the folder holding the comparisons .json files
* @property string $adminPath Path to the admin root (page id = 2)
* @property object $configData Process module settings
* @property boolean $ready To indicate tha ready() has run
*
*
* @property string $title Title
* @property string $dbMigrateSummary Summary
* @property string $dbMigrateAdditionalDetails Additional details
* @property RepeaterPageArray|RepeaterDbMigrateComparisonItemPage[] $dbMigrateComparisonItem Comparison item
* @property string $dbMigrateRestrictFields Restrict fields
* @property RepeaterPageArray|tpl_repeater_dbMigrateSnippets[] $dbMigrateSnippets Snippets
*/
class DbComparisonPage extends DbMigrationPage {
// Module constants
// Constants are set in ProcessDbMigrate
/**
* Create a new DbComparison page in memory.
*
* @param Template $tpl Template object this page should use.
*
*/
public function __construct(Template $tpl = null) {
if(is_null($tpl)) $tpl = $this->templates->get('DbComparison');
parent::__construct($tpl);
}
public function init() {
//bd('INIT COMPARISON');
}
/**
* Better to put hooks here rather than in ready.php
* This is called from ready() in ProcessDbMigrate.module as that is autoloaded
*
* @throws WireException
*
*/
public function ready() {
$this->set('adminPath', wire('pages')->get(2)->path);
$this->set('comparisons', wire('pages')->get($this->adminPath . ProcessDbMigrate::COMPARISON_PARENT));
$this->set('comparisonTemplate', wire('templates')->get(ProcessDbMigrate::COMPARISON_TEMPLATE));
$this->set('comparisonsPath', wire('config')->paths->templates . ProcessDbMigrate::COMPARISON_PATH);
$this->set('configData', wire('modules')->getConfig('ProcessDbMigrate'));
$dbMigrate = wire('modules')->get('ProcessDbMigrate');
$this->set('dbMigrate', $dbMigrate);
$this->set('dbName', $dbMigrate->dbName());
if(isset($this->configData['suppress_hooks']) && $this->configData['suppress_hooks']) $this->wire()->error("Hook suppression is on - migrations will not work correctly - unset in the module settings.");
// Fix for PW versions < 3.0.152, but left in place regardless of version, in case custom page classes are not enabled
if($this->comparisonTemplate->pageClass != __CLASS__) {
$this->comparisonTemplate->pageClass = __CLASS__;
$this->comparisonTemplate->save();
}
$this->addHookAfter("Pages::saved(template=$this->comparisonTemplate)", $this, 'afterSaved');
$this->addHookBefore("Pages::save(template=$this->comparisonTemplate)", $this, 'beforeSaveThis');
$this->set('ready', true);
}
/*
* METHODS WHICH MODIFY THE PARENT CLASS
*/
/**
*
* Refresh page from json
*
* @param null $found
* @return bool
* @throws WireException
* @throws WirePermissionException
*
*/
public function refresh($found = null) {
$this->migrationsPath = $this->comparisonsPath;
$this->migrations = $this->comparisons;
return parent::refresh($found);
}
/**
*
* Parse items, expanding selectors as necessary
* Return list of all items in format [[type, action, name, oldName], [...], ...]
*
* @return array[]
* @throws WireException
*
*/
public function listItems($type = null) {
$this->dbMigrateItem = $this->dbMigrateComparisonItem;
return parent::listItems($type);
}
/**
* @param $newOld
* @param false $noSave
* @return array|void|null
* @throws WireException
* @throws WirePermissionException
*/
public function exportData($newOld, $noSave = false) {
$this->ready();
$this->dbMigrateItem = $this->dbMigrateComparisonItem;
$this->migrationsPath = $this->comparisonsPath;
return parent::exportData($newOld, $noSave);
}
/**
* Replace image paths in RTE (Textarea) fields with the path to the file in the migration folder - for preview purposes
*
* @param string $html // Text in the RTE field
* @param string $newOld // Context - to get the file from the 'new' or 'old' directory as appropriate
* @param bool $json
* @param string $path
* @return string|string[]|null
* @throws WireException
*
*/
public function replaceImgSrcPath(string $html, string $newOld, $json = false, $path = ProcessDbMigrate::COMPARISON_PATH) {
return parent::replaceImgSrcPath($html, $newOld, $json, $path);
}
/*
* Override irrelevant functions with nulls
*/
public function afterSaved(HookEvent $event) {
}
protected function checkOverlaps($itemList) {
}
protected function beforeSaveThis(HookEvent $event) {
}
/*
* These are not overridden
*/
// protected function beforeTrashThis(HookEvent $event) {}
// protected function afterTrashedThis(HookEvent $event) {}
}