-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathpresh.php
696 lines (653 loc) · 25.5 KB
/
presh.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
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
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
<?php
/**
* @file
* presh is a command line interface for Prestashop e-commerce sites
*
* @requires PHP CLI 5.3.0, or newer.
*/
class Presh {
const SECONDS_IN_A_WEEK = 604800; // 60 * 60 * 24 * 7
/**
* Constructor
*/
public function __construct() {
define('_PS_ROOT_DIR_', getcwd());
define('_PRESH_DIR_', dirname(__FILE__));
require_once(_PS_ROOT_DIR_ . '/config/config.inc.php');
require_once(_PS_ROOT_DIR_ . '/classes/Configuration.php');
require_once(_PS_ROOT_DIR_ . '/classes/Tools.php');
require_once(_PRESH_DIR_ . '/utils.php');
}
/**
* Enables or disables the front of the shop
*
* @param string $status status to set: true to activate, false to deactivate
*/
public function activate_shop($status) {
$this->update_global_value('PS_SHOP_ENABLE', $status);
}
/**
* Toggles the activation status of the shop
*
*/
public function toggle_activation_status() {
$current_status = $this->get_global_value('PS_SHOP_ENABLE');
$this->update_global_value('PS_SHOP_ENABLE', !$current_status);
}
/**
* Enables or disables the demo mode on the Dashboard
*
* @param string $status status to set
*/
public function set_demo_mode($status) {
$this->update_global_value('PS_DASHBOARD_SIMULATION', $status);
}
/**
* Toggles the demo mode on the Dashboard
*
*/
public function toggle_demo_mode() {
$current_status = $this->get_global_value('PS_DASHBOARD_SIMULATION');
$this->update_global_value('PS_DASHBOARD_SIMULATION', !$current_status);
}
/**
* Toggles the Friendly URLs setting
*
*/
public function toggle_friendly_urls() {
$current_status = $this->get_global_value('PS_REWRITING_SETTINGS');
$this->update_global_value('PS_REWRITING_SETTINGS', !$current_status);
}
/**
* Enables or disables the Friendly URLs setting
*
* @param string $status status to set
* @param bool $generate_htaccess whether to invoke .htaccess file generation
* functionality (true by default)
*/
public function set_friendly_urls($status, $generate_htaccess = true) {
$this->update_global_value('PS_REWRITING_SETTINGS', $status);
Tools::generateHtaccess();
}
/**
* Sets the canonical URL redirection type returned by the web server
*
* @param string $type redirection type to set (0 = None, 1 = 302, 2 = 301)
*/
public function set_canonical_redirect($type) {
if ((int)$type != 1 && (int)$type != 2)
$type = 0;
$this->update_global_value('PS_CANONICAL_REDIRECT', $type);
}
/**
* Sets the domain URL of your shop
*
* @param string $domain domain URL
* @param bool $generate_htaccess whether to invoke .htaccess file generation
* functionality (true by default)
*/
public function set_shop_domain($domain, $generate_htaccess = true) {
$this->update_global_value('PS_SHOP_DOMAIN', $domain);
Tools::generateHtaccess();
}
/**
* Enables or disables several settings for debugging purposes
*
* @param string $status status to set
*/
public function set_debug_settings($status) {
$this->update_global_value('PS_DISABLE_NON_NATIVE_MODULE', $status);
$this->update_global_value('PS_DISABLE_OVERRIDES', $status);
}
/**
* Enables or disables several settings for peformance purposes
* through CCC (Combine, Compress and Cache)
*
* @param string $status status to set
*/
public function optimize_via_ccc($status) {
$this->update_global_value('PS_CSS_THEME_CACHE', $status);
$this->update_global_value('PS_JS_THEME_CACHE', $status);
$this->update_global_value('PS_HTML_THEME_COMPRESSION', $status);
$this->update_global_value('PS_JS_HTML_THEME_COMPRESSION', $status);
$this->update_global_value('PS_JS_DEFER', $status);
$this->update_global_value('PS_HTACCESS_CACHE_CONTROL', $status);
}
/**
* Enables SMTP mail method and configures its related fields
*
* @param string $mail_domain fully qualified domain name for mails
* @param string $mail_server IP address or server name
* @param string $mail_user optional smtp user
* @param string $mail_passwd optional smtp password
* @param string $encryption_mode encryption protocol to use ('off' by default)
* @param string $port smtp port number to use (25 by default)
*/
public function set_smtp_mailing($mail_domain, $mail_server, $mail_user,
$mail_passwd, $encryption_mode = 'off', $port = '25') {
$this->update_global_value('PS_MAIL_METHOD', 2); // "2" means "use SMTP"
$this->update_global_value('PS_MAIL_DOMAIN', $mail_domain);
$this->update_global_value('PS_MAIL_SERVER', $mail_server);
if ($mail_user != null && strlen($mail_user) > 0) {
$this->update_global_value('PS_MAIL_USER', $mail_user);
}
if ($mail_passwd != null && strlen($mail_passwd) > 0) {
$this->update_global_value('PS_MAIL_PASSWD', $mail_passwd);
}
if ($encryption_mode != null) {
$encryption_mode = strtolower($encryption_mode);
if ($encryption_mode == 'off' || $encryption_mode == 'tls' || $encryption_mode == 'ssl')
$this->update_global_value('PS_MAIL_SMTP_ENCRYPTION', $encryption_mode);
}
$this->update_global_value('PS_MAIL_SMTP_PORT', $port);
}
/**
* Updates a global configuration variable, given its key name and new value
*
* @param string $key name of the variable to globally update
* @param string $value new value to globally set on the given variable
* @return bool true when successfully updated, false otherwise
*/
public function update_global_value($key, $value) {
return Configuration::updateGlobalValue($key, $value);
}
/**
* Gets a global configuration variable, given its key name
*
* @param string $key name of the variable to globally get
* @return string value of the given key
*/
public function get_global_value($key) {
return Configuration::getGlobalValue($key);
}
/**
* Updates a database table column, given its name, column and new value.
* Its goal is to serve as a quick way to update some module option or, in
* a more general sense, to update one or more columns of a given table,
* optionally given a where clause
*
* @param string $table name of the table to update
* @param string $data associative array containing column's values
* @param string $where optional where condition
* @return bool true when successfully updated, false otherwise
*/
public function update_table($table, $data, $where = '') {
// we need $data as array, not as string
eval("\$data = $data;");
return Db::getInstance()->update($table, $data, $where);
}
/**
* Installs a module given its name. The module has to be present on Prestashop
* modules directory
*
* @param string $name name of the module to install
* @return bool true when successfully installed, false otherwise
*/
public function install_module($name) {
$module_instance = Module::getInstanceByName($name);
return $module_instance->install();
}
/**
* Uninstalls a module given its name. The module has to be present on
* Prestashop modules directory
*
* @param string $name name of the module to uninstall
* @return bool true when successfully uninstalled, false otherwise
*/
public function uninstall_module($name) {
$module_instance = Module::getInstanceByName($name);
return $module_instance->uninstall();
}
/**
* Enables a module given its name.
* It is expected to have a module directory inside
* Prestashop modules directory named like the 'name' parameter
*
* @param string $name name of the module to enable
* @return bool true when successfully enabled, false otherwise
*/
public function enable_module($name) {
return Module::enableByName($name);
}
/**
* Disables a module given its name.
* It is expected to have a module directory inside
* Prestashop modules directory named like the 'name' parameter
*
* @param string $name name of the module to disable
* @return bool true when successfully disabled, false otherwise
*/
public function disable_module($name) {
return Module::disableByName($name);
}
/**
* Lists installed modules in the store
*
*/
public function list_modules_installed() {
foreach(Module::getModulesInstalled() as $m)
echo $m['name'] . "\n";
}
/**
* Downloads a module given its url to the Prestashop modules directory.
* The downloaded file is expected to be in zip format.
* It is also expected the uncompressed file will contain a module as first directory.
*
* @param string $url url to download the module from
* @return bool true when successfully downloaded, false otherwise
*/
public function download_foreign_module($url) {
# TODO: some servers, like www.eolia.o2switch.net for newsletteradmin module
# require the User Agent header, so something like curl will be needed
# to download files from them
$file_handle = Utils::write_to_temp_file(Tools::file_get_contents($url));
$file_path = Utils::get_path_of_file_handle($file_handle);
$file_type = Utils::get_file_magic_type($file_path);
switch ($file_type) {
case "application/zip":
return Tools::ZipExtract($file_path, _PS_ROOT_DIR_ . '/modules/');
break;
default:
return false;
}
}
/**
* Updates as many modules as possible from the Prestashop modules directory.
*
*/
public function update_modules() {
$lang = $this->get_global_value('PS_LOCALE_LANGUAGE');
$country = $this->get_global_value('PS_LOCALE_COUNTRY');
$xml_file = _PS_ROOT_DIR_ . '/config/xml/modules_native_addons.xml';
$this->update_modules_xml_file($xml_file, 'native_all');
$xml_content = Tools::file_get_contents($xml_file);
$xml_tree = @simplexml_load_string($xml_content, null, LIBXML_NOCDATA);
$modules_to_update = array();
$modules_on_disk = Module::getModulesOnDisk(true, false, 1);
foreach($modules_on_disk as $module) {
// it seems some modules (like 'blockbanner') can have its 'installed'
// attribute empty, so it's better to update it anyway
//if ($module->installed != true)
// continue;
Module::initUpgradeModule($module);
foreach($xml_tree->module as $modaddons) {
if($module->name == $modaddons->name) {
if (Tools::version_compare($module->version, $modaddons->version, '<')) {
$modules_to_update[$module->name]['id'] = $modaddons->id;
}
}
}
}
foreach($modules_to_update as $module_name => $module) {
$file_handle = Utils::write_to_temp_file(Tools::addonsRequest('module',
array('iso_lang' => $lang, 'iso_code' => $country,
'id_module' => $module['id'])));
$file_path = Utils::get_path_of_file_handle($file_handle);
$file_type = Utils::get_file_magic_type($file_path);
switch($file_type) {
case "application/zip":
Tools::ZipExtract($file_path, _PS_ROOT_DIR_ . '/modules/');
# TODO: log result of extraction/updating
# because I am not sure if updating is done at this step
default:
continue;
}
$module_instance = Module::getInstanceByName($module_name);
if (Module::needUpgrade($module_instance) == true) {
$module_instance->runUpgradeModule();
}
}
}
/**
* Updates a given file with the contents available in the Prestashop
* addons online resource. It is assumed that the given file exists inside
* the /config/xml/ subdirectory of a Prestashop installation.
*
* @param string $file xml file to update
* @param string $request_type type of request to use with the addons web site
* @param int $timeout max age, in seconds, of the given file to be considered
* as updated before doing a new update
*/
public function update_modules_xml_file($file, $request_type, $timeout = SECONDS_IN_A_WEEK) {
$file_age = 0;
if (file_exists($file) && filesize($file) > 0)
$file_age = time() - filemtime($file);
if ($file_age >= $timeout || $file_age == 0)
file_put_contents($file, Tools::addonsRequest($request_type));
}
/**
* Gets the installation directory of Prestashop
*
* @return string installation directory
*/
public function get_install_dir() {
return _PS_ROOT_DIR_;
}
/**
* Gets the running version of Prestashop
*
* @return string running Prestashop version
*/
public function get_running_version() {
return $this->get_global_value('PS_VERSION_DB');
}
/**
* Tries to fix Prestashop issues with mail sending via SSL/TLS
*
* @param bool $reverse indicates wheter a reverse patch will be applied, so changes
* to Prestashop core files will be reverted. It is false by default, so a forward
* patch will be applied
* @param bool $try_to_get_swift flags if a suitable version of Swift Mailer library
* will be downloaded if needed. It is true by default
* @return bool the result of trying to apply the patch file
*
*/
public function fix_mail($reverse = false, $try_to_get_swift = true) {
if ($reverse == true)
Tools::deleteDirectory(_PS_ROOT_DIR_ . '/tools/swift5/lib');
// get Swift Mailer
if ($try_to_get_swift == true && $reverse == false)
$this->get_swift_mailer_library();
require_once(_PRESH_DIR_ . '/fix_mail_encryption/fix.php');
$fm = new FixMail();
return $fm->apply_patch($this->get_running_version(),
$this->get_install_dir(), $reverse);
}
/**
* Downloads Swift Mailer library
*
* @param string $url URL to download Swift Mailer from. If none specified
* it will be gotten from its official GitHub repository
* @param string $version Swift Mailer version to get (5.2.2 by default)
*
*/
public function get_swift_mailer_library($url = '', $version = '5.2.2') {
$dst_lib_dir = _PS_ROOT_DIR_ . '/tools/swift5/lib';
if (file_exists($dst_lib_dir)) // do nothing if already exists
return;
else
mkdir($dst_lib_dir, 0755, true); // or create it if not exists
if ($url == null || $url == '') {
$url = 'https://github.com/swiftmailer/swiftmailer/archive/v' . $version . '.zip';
}
$tmp_dir = Utils::create_temp_dir();
$src_lib_dir = $tmp_dir . DIRECTORY_SEPARATOR . 'swiftmailer-' . $version . DIRECTORY_SEPARATOR . 'lib';
$file_handle = Utils::write_to_temp_file(Tools::file_get_contents($url));
$file_path = Utils::get_path_of_file_handle($file_handle);
$file_type = Utils::get_file_magic_type($file_path);
switch ($file_type) {
case "application/zip":
Tools::ZipExtract($file_path, $tmp_dir);
break;
default:
return;
}
Tools::recurseCopy($src_lib_dir, $dst_lib_dir);
Tools::deleteDirectory($tmp_dir);
}
/**
* Wipes out the catalog, sales and stores data of a Prestashop installation,
* hopefully being the sample data installed by default. This is a dangerous
* and potentially destructive operation, because it can evaporate your real
* products, categories, sales and related data. This function internally
* uses the 'pscleaner' module
*
* @param string $confirmation Fixed string expected to confirm you are
* not mad. It is null by default so it is required to explicitly pass a first
* argument expected to be "Do It, I Am Completely Sure This Will Destroy My Data"
* if you really want to evaporate the data (there is no 'undo' option)
* @param bool $verify_is_only_sample_data flag to check if the database contains
* only the sample data loaded by the installer, prior to attempt the cleaning
* @param bool $restore_initial_status flag to indicate the uninstalling and/or
* deletion of the 'pscleaner' module, so its state is the same it had at the
* beginning of this function
*
*/
public function clean_sample_data($confirmation = null,
$restore_initial_status = true,
$verify_is_only_sample_data = true) {
// TODO: review what is useful here
// http://stackoverflow.com/questions/15277017/prestashop-delete-all-testing-data-before-production
// http://maiolab.net/deleting-demo-data-in-default-prestashop-database/
if ($confirmation == null || $confirmation != 'Do It, I Am Completely Sure This Will Destroy My Data')
return;
if ($verify_is_only_sample_data) {
if (!$this->is_only_sample_data_installed())
return;
}
$mod_dir = _PS_ROOT_DIR_ . '/modules/pscleaner/';
$initially_installed = Module::isInstalled('pscleaner');
$initially_enabled = Module::isEnabled('pscleaner');
$initially_exists_dir = file_exists($mod_dir);
if (!$initially_installed) {
$xml_file = _PS_ROOT_DIR_ . '/config/xml/modules_native_addons.xml';
$xml_raw_content = Tools::file_get_contents($xml_file);
$id = null;
if ($xml_tree = simplexml_load_string($xml_raw_content, null, LIBXML_NOCDATA))
foreach($xml_tree->module as $modaddons) {
if ('pscleaner' == $modaddons->name) {
$id = $modaddons->id;
break;
}
}
if ($id) {
$file_handle = Utils::write_to_temp_file(Tools::addonsRequest('module', array('id_module' => pSQL($id))));
$file_path = Utils::get_path_of_file_handle($file_handle);
$file_type = Utils::get_file_magic_type($file_path);
switch ($file_type) {
case "application/zip":
Tools::ZipExtract($file_path, _PS_ROOT_DIR_ . '/modules/');
break;
default:
return;
}
$this->install_module('pscleaner');
}
} // end if (!$initially_installed)
if (!Module::isEnabled('pscleaner'))
$this->enable_module('pscleaner');
$module_instance = Module::getInstanceByName('pscleaner');
if ($module_instance) {
$module_instance->truncate('catalog');
$module_instance->truncate('sales');
}
//
if ($restore_initial_status) {
if (!$initially_enabled)
$this->disable_module('pscleaner');
if (!$initially_installed)
$this->uninstall_module('pscleaner');
if (!$initially_exists_dir)
Tools::deleteDirectory($mod_dir);
}
// TODO: propose to 'pscleaner' developers some code to clean
// sample stores and then remove this part
Db::getInstance()->executeS('TRUNCATE TABLE `' . _DB_PREFIX_ . 'store`');
Db::getInstance()->executeS('TRUNCATE TABLE `' . _DB_PREFIX_ . 'store_shop`');
foreach (scandir(_PS_STORE_IMG_DIR_) as $file_or_dir) {
if (preg_match('/^[0-9]+(\-(.*))?\.jpg$/', $file_or_dir) &&
is_file(_PS_STORE_IMG_DIR_ . $file_or_dir)) {
unlink(_PS_STORE_IMG_DIR_ . $file_or_dir);
}
}
// banners in themeconfigurator hooks
Db::getInstance()->executeS('TRUNCATE TABLE `' . _DB_PREFIX_ . 'themeconfigurator`');
// slides in homeslider
// TODO: propose to 'pscleaner' developers some code to clean
// sample slides and then remove this part
Db::getInstance()->executeS('TRUNCATE TABLE `' . _DB_PREFIX_ . 'homeslider`');
Db::getInstance()->executeS('TRUNCATE TABLE `' . _DB_PREFIX_ . 'homeslider_slides`');
Db::getInstance()->executeS('TRUNCATE TABLE `' . _DB_PREFIX_ . 'homeslider_slides_lang`');
foreach (scandir(_PS_MODULE_DIR_ . 'homeslider/images/') as $file_or_dir) {
if (preg_match('/^sample-[123]\.jpg$/', $file_or_dir) &&
is_file(_PS_MODULE_DIR_ . 'homeslider/images/' . $file_or_dir)) {
unlink(_PS_MODULE_DIR_ . 'homeslider/images/' . $file_or_dir);
}
}
// info blocks near footer
Db::getInstance()->executeS('TRUNCATE TABLE `' . _DB_PREFIX_ . 'info`');
Db::getInstance()->executeS('TRUNCATE TABLE `' . _DB_PREFIX_ . 'info_lang`');
}
/**
* Review customers, products, categories and stores data to check if it only
* corresponds to the sample data of catalog and sales loaded by the
* Prestashop installer, also checking if the Prestashop version installed
* is compatible with this function
* @return bool true if only sample data is present, false otherwise
*
*/
public function is_only_sample_data_installed() {
if (!(Tools::version_compare($this->get_running_version(), '1.6.0.0', '>=') &&
Tools::version_compare($this->get_running_version(), '1.6.0.9', '<=')))
return false;
// a) john doe
$customers = Customer::getCustomers();
if (count($customers) != 1)
return false;
$customer_john = $customers[0];
if (!($customer_john['email'] == '[email protected]' &&
$customer_john['firstname'] == 'John' &&
$customer_john['lastname'] == 'DOE'))
return false;
// b) products
$id_lang = Context::getContext()->language->id;
$sample_products = Product::getProducts($id_lang, 0, 0, 'name', 'asc');
if (count($sample_products) != 7)
return false;
//$sample_products_names = array_column($sample_products, 'name'); // requires PHP >= 5.5
$sample_products_names = array_map(function ($v){ return $v['name']; }, $sample_products);
asort($sample_products_names);
$expected_products_names = array('Blouse', 'Faded Short Sleeve T-shirts',
'Printed Chiffon Dress', 'Printed Dress', 'Printed Dress',
'Printed Summer Dress', 'Printed Summer Dress'
);
asort($expected_products_names);
if (count(array_diff($sample_products_names, $expected_products_names)) != 0)
return false;
// c) categories
// Category::getCategories($id_lang, false)
// Category::getNestedCategories(null, $id_lang, false)
// Category::getSimpleCategories($id_lang)
// Category::getHomeCategories($id_lang, false)
// Category::getRootCategory($id_lang)
$simple_categories = Category::getSimpleCategories($id_lang);
if (count($simple_categories) != 10)
return false;
$root_category = Category::getRootCategory($id_lang);
$sample_categories = array_filter($simple_categories,
function($it) use($root_category) {
return $it['id_category'] != $root_category->id_category;
}
);
$sample_categories_names = array_map(function ($v){ return $v['name']; }, $sample_categories);
asort($sample_categories_names);
$expected_categories_names = array('Blouses', 'Casual Dresses',
'Dresses', 'Evening Dresses', 'Summer Dresses', 'T-shirts',
'Tops', 'Tops', 'Women'
);
asort($expected_categories_names);
if (count(array_diff($sample_categories_names, $expected_categories_names)) != 0)
return false;
// d) stores
$sample_stores = Db::getInstance()->executeS('SELECT name from ' . _DB_PREFIX_. 'store');
if (count($sample_stores) != 5)
return false;
$sample_stores_names = array_map(function ($v){ return $v['name']; }, $sample_stores);
asort($sample_stores_names);
$expected_stores_names = array('Coconut Grove', 'Dade County',
'E Fort Lauderdale', 'N Miami/Biscayne', 'Pembroke Pines'
);
if (count(array_diff($sample_stores_names, $expected_stores_names)) != 0)
return false;
// e) banners in themeconfigurator
$sample_tc_banners = Db::getInstance()->executeS('SELECT image from ' . _DB_PREFIX_. 'themeconfigurator');
if (count($sample_tc_banners) != 7)
return false;
$sample_tc_banners_images = array_map(function ($v){ return $v['image']; }, $sample_tc_banners);
asort($sample_tc_banners_images);
$expected_tc_banners_images = array('banner-img1.jpg', 'banner-img2.jpg',
'banner-img3.jpg', 'banner-img4.jpg', 'banner-img5.jpg',
'banner-img6.jpg', 'banner-img7.jpg'
);
if (count(array_diff($sample_tc_banners_images, $expected_tc_banners_images)) != 0)
return false;
// f) slides in homeslider
$sample_slides = Db::getInstance()->executeS('SELECT image from ' . _DB_PREFIX_. 'homeslider_slides_lang');
if (count($sample_slides) != 3)
return false;
$sample_slides_images = array_map(function ($v){ return $v['image']; }, $sample_slides);
asort($sample_slides_images);
$expected_slides_images = array('sample-1.jpg', 'sample-2.jpg',
'sample-3.jpg'
);
if (count(array_diff($sample_slides_images, $expected_slides_images)) != 0)
return false;
// g) info blocks in front page
$sample_info_blocks = Db::getInstance()->executeS('SELECT text from ' . _DB_PREFIX_. 'info_lang');
if (count($sample_info_blocks) != 2)
return false;
$pattern = '/Lorem ipsum/';
foreach($sample_info_blocks as $info_block) {
if (preg_match($pattern, $info_block['text']) != 1)
return false;
}
// if all test passed, then it is only sample data
return true;
}
/**
* Encrypts a given value, which is supposed to be unique for the current shop
*
* @param string $value value to encrypt
* @return string encrypted value
*/
public function encrypt($value = '') {
return Tools::encrypt($value);
}
/**
* Encrypts and prints a given value, which is supposed to be unique for the current shop
*
* @param string $value value to encrypt
*/
public function encrypt_and_print($value) {
echo $this->encrypt($value);
}
/**
* Runs given file on Prestashop environment
*
* @param string $file value to run
*/
public function run($file){
if(is_readable ($file)){
$argv = func_get_args();
return require($file);
}
}
/**
* Deletes the cache classes index file at cache/class_index.php
*
* @return bool true if the file is deleted
*/
public function delete_cache_class_index_file($value) {
return unlink(_PS_ROOT_DIR_ . '/cache/class_index.php');
}
/**
* Shows the available functionality of Presh
*
*/
public function help() {
$methods = get_class_methods($this);
foreach($methods as $m) {
if ($m != '__construct')
echo "\t$m\n";
}
}
/**
* Shows the current version of Presh
*
*/
public function version() {
echo "0.2.0-alpha";
echo "\n";
}
}
?>