-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathsynchonizeclass.sh
executable file
·347 lines (315 loc) · 11.4 KB
/
synchonizeclass.sh
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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
#!/usr/bin/env bash
##
# Copyright (C) 2018-2019 thirty bees
#
# @author thirty bees <[email protected]>
# @copyright 2018-2019 thirty bees
# @license proprietary
function usage {
echo "Usage: synchronizeclass.sh [-h|--help] <class file> [<core class file>]"
echo
echo "This script synchonizes a class with thirty bees core."
echo
echo " -h, --help Show this help and exit."
echo
echo " <class file> Name of the class or better, name of the file"
echo " containing the class. Even better: full path"
echo " of the file containing the class in this module."
echo
echo " In the simple variants, the script tries to"
echo " figure the remaining parts."
echo
echo " <core class file> If the script can't find this file on its own,"
echo " path of the file in thirty bees core to"
echo " synchronize with. Default is to search it"
echo " automatically."
echo
echo "Example:"
echo
echo " ./synchronizeclass.sh Shop"
echo
echo "If this doesn't work:"
echo
echo " ./synchronizeclass.sh Shop.php"
echo
echo "If this still doesn't work:"
echo
echo " ./synchronizeclass.sh classes/Shop.php"
echo
echo "If this still doesn't work:"
echo
echo " ./synchronizeclass.sh classes/Shop.php ../../classes/shop/Shop.php"
echo
echo "Use Gitk to evaluate the result and Git to add it to the repository."
echo
}
### Auxilliary functions.
function e {
echo "${1} Aborting."
exit 1
}
### Options parsing.
FILE_SOURCE=''
FILE_TARGET=''
while [ ${#} -ne 0 ]; do
case "${1}" in
'-h'|'--help')
usage
exit 0
;;
*)
if [ -z "${FILE_TARGET}" ]; then
FILE_TARGET="${1}"
elif [ -z "${FILE_SOURCE}" ]; then
FILE_SOURCE="${1}"
else
e "Too many arguments. Try --help."
fi
;;
esac
shift
done
### Finding source and target.
CLASS="${FILE_TARGET##*/}"
CLASS="${CLASS%.php}"
if [ "${FILE_TARGET}" = "${FILE_TARGET%.php}" ]; then
FILE_TARGET="${FILE_TARGET}.php"
fi
if [ ! -r "${FILE_TARGET}" ]; then
FILE_TARGET=$(find classes -name "${FILE_TARGET}")
fi
if [ ! -r "${FILE_TARGET}" ]; then
e "Can't find local class file for ${CLASS}, please specify it exactly."
fi
if [ ! -r "${FILE_SOURCE}" ]; then
FILE_SOURCE=$(find ../../classes -name "${FILE_TARGET##*/}")
fi
if [ ! -r "${FILE_SOURCE}" ]; then
e "Can't find source class file ${CLASS}, please specify it exactly."
fi
### Do the synchonization.
echo "Syncronizing ${FILE_TARGET} to ${FILE_SOURCE}"
sed '
# Header only.
/^<?php$/, /^ \*\/$/ {
# Fix license stuff and switch from OSL to AFL license.
s/@license http:\/\/opensource.org\/licenses\/osl-3.0.php/@license /
s/Open Software License (OSL 3.0)/Academic Free License (AFL 3.0)/
s/licenses\/osl-3.0.php/licenses\/afl-3.0.php/
# Add namespace after the header.
s/^ \*\/$/&\n\nnamespace PsOneSixMigrator;/
}
# Remove "Core" from class name.
s/\([Cc]lass\s\+\w\+\)Core/\1/
# PHP core class replacements to deal with the isolated namespace.
# \b = word boundary, \\\? for an optional already existing backslash.
s/\\\?\bArrayAccess\b/\\ArrayAccess/g
s/\\\?\bCountable\b/\\Countable/g
s/\\\?\bDateTime\b/\\DateTime/g
s/\\\?\bDateTimeZone\b/\\DateTimeZone/g
s/\\\?\bIterator\b/\\Iterator/g
s/\\\?\bmysqli_result\b/\\mysqli_result/g
s/\\\?\bPDO\b/\\PDO/g
s/\\\?\bPDOStatement\b/\\PDOStatement/g
s/\\\?\bSimpleXMLElement\b/\\SimpleXMLElement/g
s/\\\?\bReflectionClass\b/\\ReflectionClass/g
s/\\\?\bZipArchive\b/\\ZipArchive/g
# Various other replacements to deal with the isolated namespace.
s/\\\?\bAdapter_Exception\b/\\Exception/g
s/\\\?\bPrestaShopException\b/\\Exception/g
s/\\\?\bPrestaShopDatabaseException\b/\\Exception/g
# Unused PS/thirty bees stuff. Point to the core implementation.
s/\\\?\bWebserviceRequest\b/\\WebserviceRequest/g
# Remove obsolete stuff.
s/\s\+implements\s\+Core_Foundation_Database_EntityInterface//
' < "${FILE_SOURCE}" > "${FILE_TARGET}"
### Function fixes.
#
# Most of them just described as recommended manual fixes.
#
# These were found when comparing module class files of version 1.0.2 with
# core class files of Git version 1.0.6~1620 (which was about the closest match
# then).
case "${CLASS}" in
'Context')
echo "Known required manual tweaks:"
echo " - Delete Context->getMobileDevice()."
echo " - Delete Context->checkMobileContext()."
echo " - Delete Context->getMobileDetect()."
echo "... and each of their usage. is_tablet, is_mobile always false."
;;
'Db')
sed -i '
/public static function getClass()/ {
n
a \'" return (__NAMESPACE__ ? __NAMESPACE__.'\\\\\\\\' : '').'DbPDO';"'
p; N; d;
}
' "${FILE_TARGET}"
;;
'Dispatcher')
echo "Known required manual tweaks:"
echo " - Delete Dispatcher::getModuleControllers()."
echo " - Delete Dispatcher::dispatch()."
echo " - Remove all code but the last line in Dispatcher::supplierID()."
echo " - Remove all code but the last line in Dispatcher::manufacturerID()."
echo " - Remove all code but the last line in Dispatcher::productID()."
echo " - Remove all code but the last line in Dispatcher::categoryID()."
echo " - Remove all code but the last line in Dispatcher::cmsID()."
echo " - Remove all code but the last line in Dispatcher::cmsCategoryID()."
;;
'Group')
echo "Known required manual tweaks:"
echo " - Delete Group::getReduction()."
echo " - Delete Group::add()."
;;
'Hook')
echo "Known required manual tweaks:"
echo " - Replace all code in Hook::exec() with just 'return;'"
echo " - Replace all code in Hook::getHookModuleExecList() with just 'return [];'"
echo " - Delete Hook::execWithoutCache()."
echo " - Delete Hook::coreCallHook()."
echo " - Delete Hook::postUpdateOrderStatus()."
echo " - Delete Hook::orderConfirmation()."
echo " - Delete Hook::updateOrderStatus()."
echo " - Delete Hook::paymentReturn()."
;;
'Language')
echo "Known required manual tweaks:"
echo " - Delete Language::updateModulesTranslations()."
echo " - Delete Language::downloadAndInstallLanguagePack()."
echo " - Delete Language::checkAndAddLanguage()."
echo " - Delete Language::deleteSelection()."
echo " - Delete Language::delete()."
echo " - Delete Language::_copyNoneFlag()."
echo " - Delete Language::moveToIso()."
echo " - Delete Language::_getThemesList()."
echo " - Delete Language::checkFiles()."
echo " - Delete Language::checkFilesWithIsoCode()."
echo " - Delete Language::getFilesList()."
;;
'ObjectModel')
echo "Known required manual tweaks:"
echo " - Delete ObjectModel::getWebserviceParameters()."
echo " - Delete ObjectModel::getWebserviceObjectList()."
echo " - Delete ObjectModel::deleteImage()."
;;
'Shop')
echo "Known required manual tweaks:"
echo " - Delete Shop::getAddress()."
echo " - Delete Shop::getUrlsSharedCart()."
echo " - Delete Shop::getGroup()."
echo " - Delete Shop::getContextShopGroup()."
echo " - Delete Shop::copyShopData()."
;;
'Tab')
echo "Known required manual tweaks:"
echo " - Delete Tab::checkTabRights()."
echo " - Delete Tab::getTabModulesList()."
;;
'Tools')
echo "Known required manual tweaks:"
echo " - Delete Tools::getCountry()."
echo " - Delete Tools::setCurrency()."
echo " - Delete Tools::displayPriceSmarty()."
echo " - Delete Tools::displayPrice()."
echo " - Delete Tools::convertPrice()."
echo " - Delete Tools::convertPriceFull()."
echo " - Delete Tools::dieOrLog()."
echo " - Delete Tools::throwDeprecated()."
echo " - Remove all usages of Tools::throwDeprecated(), without replacement."
echo " - Delete Tools::clearXMLCache()."
echo " - Delete Tools::getMetaTags()."
echo " - Delete Tools::getHomeMetaTags()."
echo " - Delete Tools::completeMetaTags()."
echo " - Delete Tools::getFullPath()."
echo " - Delete Tools::getPath()."
echo " - Delete Tools::orderbyPrice()."
echo " - Delete Tools::minifyHTML()."
echo " - Delete Tools::minifyHTMLpregCallback()."
echo " - Delete Tools::packJSinHTML()."
echo " - Delete Tools::packJSinHTMLpregCallback()."
echo " - Delete Tools::packJS()."
echo " - Delete Tools::minifyCSS()."
echo " - Delete Tools::replaceByAbsoluteURL()."
echo " - Delete Tools::cccCss()."
echo " - Delete Tools::cccJS()."
echo " - Delete Tools::generateIndex()."
echo " - Delete Tools::clearColorListCache()."
echo " - Remove all code but the last line in Tools::purifyHTML()."
echo " - Delete Tools::parserSQL()."
;;
'Translate')
echo "Known required manual tweaks:"
echo " - Delete Translate::getAdminTranslation()."
;;
'Upgrader')
echo "CAUTION: this class is pretty distinct from thirty bees core."
echo " Attempts to synchonize it have failed before. Probably"
echo " it's a good idea to keep this class unsynchonized."
echo
echo "Known (but incomplete) required manual tweaks:"
echo "Add 'use PsOneSixMigrator\GuzzleHttp\Client;' to the header."
echo "Add 'use PsOneSixMigrator\GuzzleHttp\Promise;' to the header."
echo "Add 'use PsOneSixMigrator\SemVer\Expression;' to the header."
echo "Add 'use PsOneSixMigrator\SemVer\Version;' to the header."
;;
'Validate')
echo "Known required manual tweaks:"
echo " - Replace all code inside Validate::isEmail() with 'return true;'."
;;
esac
### Documentation.
# About the state of synchronization of class files with thirty bees core.
#
# All the files in classes/ are copies of the files in thirty bees core, with
# only few modifications. The idea is to have this module entirely independent
# from core files, because these core files get changes during migration,
# potentially breaking them for a short moment.
#
# All these files were added shortly after emerging module 'psonesixmigrator'
# from PrestaShop's module 'autoupdater', before release 1.0.0 of
# 'psonesixmigrator'.
#
# One can use this command to find the distinction between the class here and
# the class in thirty bees core. The Git version with the smallest number shows
# the closest match, which is likely the moment it was copied:
#
# for V in {1..2500}; do
# git checkout 1.0.7~$V classes/shop/Shop.php
# N=$(diff -w -u0 classes/shop/Shop.php modules.off/psonesixmigrator/classes/Shop.php | wc -l)
# echo "$V $N"
# done
#
# It turned out that Git version 1.0.7~1620 is the closest match for most
# classes. Number of diff lines for this core version and version 1.0.2 in this
# module:
#
# classes/AbstractLogger.php: 134
# classes/Blowfish.php: 18
# classes/Cache.php: 10
# classes/CacheFs.php: 23
# classes/Configuration.php: 16
# classes/ConfigurationTest.php: 739
# classes/Context.php: 114
# classes/CryptBlowfish.php: 73
# classes/DbPDO.php: 533
# classes/Db.php: 1118
# classes/DbQuery.php: 283
# classes/Dispatcher.php: 22
# classes/Employee.php: 37
# classes/FileLogger.php: 97
# classes/Group.php: 10
# classes/Hook.php: 22
# classes/Language.php: 24
# classes/ObjectModel.php: 3313
# classes/PrestaShopCollection.php: 49
# classes/Shop.php: 23
# classes/ShopUrl.php: 182
# classes/Tab.php: 10
# classes/Tools.php: 1357
# classes/Translate.php: 10
# classes/Upgrader.php: 580
# classes/Validate.php: 10
#