|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
use yii\db\Migration; |
|
4
|
|
|
|
|
5
|
|
|
/** |
|
6
|
|
|
* Class m190204_134239_firefly_interface_change_db_fix |
|
7
|
|
|
* Converts old API firefly action links to new api links. |
|
8
|
|
|
* These become hardcoded when adding images to wysiwyg |
|
9
|
|
|
*/ |
|
10
|
|
|
class m190204_134239_firefly_interface_change_db_fix extends Migration |
|
11
|
|
|
{ |
|
12
|
|
|
/** |
|
13
|
|
|
* This is the old api url that will no longer exist |
|
14
|
|
|
* @var string |
|
15
|
|
|
*/ |
|
16
|
|
|
private $upSearch = '/firefly/get/img'; |
|
17
|
|
|
/** |
|
18
|
|
|
* This is the new api link to convert to |
|
19
|
|
|
* @var string |
|
20
|
|
|
*/ |
|
21
|
|
|
private $upReplace = '/firefly/file/img'; |
|
22
|
|
|
|
|
23
|
|
|
public function safeUp() |
|
24
|
|
|
{ |
|
25
|
|
|
return $this->convertFireflyGetsToFiles($this->upSearch, $this->upReplace); |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
public function safeDown() |
|
29
|
|
|
{ |
|
30
|
|
|
return $this->convertFireflyGetsToFiles($this->upReplace, $this->upSearch); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
private function convertFireflyGetsToFiles($search, $replace) |
|
34
|
|
|
{ |
|
35
|
|
|
$potentiallyAffected = $this->db->createCommand("SELECT `class_type`, `member_ref` FROM `dds_member` WHERE `data_type_ref`='textlong'")->queryAll(); |
|
36
|
|
|
if (count($potentiallyAffected)==0) |
|
37
|
|
|
return; |
|
38
|
|
|
$classes = []; |
|
39
|
|
|
foreach ($potentiallyAffected as $pa) |
|
40
|
|
|
$classes[$pa['class_type']][] = $pa['member_ref']; |
|
41
|
|
|
$phoebeClasses = array_keys($classes); |
|
42
|
|
|
$phoebe = neon('phoebe')->getIPhoebeType('daedalus'); |
|
43
|
|
|
|
|
44
|
|
|
$phoebeDefinition = []; |
|
45
|
|
|
foreach ($phoebeClasses as $pc) |
|
46
|
|
|
$phoebeDefinition[$pc] = $phoebe->getClass($pc, null, false); |
|
47
|
|
|
|
|
48
|
|
|
$potentiallyAffectedLookup = []; |
|
49
|
|
|
foreach ($potentiallyAffected as $pa) { |
|
50
|
|
|
if (empty($potentiallyAffectedLookup[$pa['class_type']])) |
|
51
|
|
|
$potentiallyAffectedLookup[$pa['class_type']] = []; |
|
52
|
|
|
$potentiallyAffectedLookup[$pa['class_type']][] = $pa['member_ref']; |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
$wysiwygFields = []; |
|
56
|
|
|
foreach ($phoebeDefinition as $pdKey => $pd) { |
|
57
|
|
|
$fields = !empty($pd->definition['fields']) ? $pd->definition['fields'] : null; |
|
58
|
|
|
if ($fields) { |
|
59
|
|
|
$potentials = !empty($potentiallyAffectedLookup[$pdKey]) ? $potentiallyAffectedLookup[$pdKey] : []; |
|
60
|
|
|
foreach ($fields as $field) { |
|
61
|
|
|
if (in_array($field['name'], $potentials)) { |
|
62
|
|
|
if ($field['definition']['class'] == "neon\\core\\form\\fields\\Wysiwyg") { |
|
63
|
|
|
$wysiwygFields[$pdKey] = !empty($wysiwygFields[$pdKey]) ? $wysiwygFields[$pdKey] : []; |
|
64
|
|
|
$wysiwygFields[$pdKey][] = $field['name']; |
|
65
|
|
|
} |
|
66
|
|
|
} |
|
67
|
|
|
} |
|
68
|
|
|
} |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
$dds = neon('dds')->IDdsObjectManagement; |
|
|
|
|
|
|
72
|
|
|
foreach ($wysiwygFields as $classType => $fields) { |
|
73
|
|
|
$start=0; |
|
74
|
|
|
do { |
|
75
|
|
|
$found = $dds->listObjects($classType, $total, true, true, $start, 100); |
|
|
|
|
|
|
76
|
|
|
$start += count($found); |
|
77
|
|
|
foreach ($found as $objectData) { |
|
78
|
|
|
$changes = []; |
|
79
|
|
|
foreach ($fields as $field) { |
|
80
|
|
|
if (!empty($objectData[$field]) && strpos($objectData[$field],$search)!==false) |
|
81
|
|
|
$changes[$field] = str_replace($search, $replace, $objectData[$field]); |
|
82
|
|
|
} |
|
83
|
|
|
if (count($changes)) { |
|
84
|
|
|
$dds->editObject($objectData['_uuid'], $changes); |
|
85
|
|
|
} |
|
86
|
|
|
} |
|
87
|
|
|
} while (count($found)>0); |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
return true; |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
} |
|
94
|
|
|
|