PluginProbe
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress / 10.9.1
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress v10.9.1
11.1.1 11.1.0 11.0.5 11.0.4 11.0.3 11.0.2 11.0.1 11.0.0 10.11.1 10.11.0 10.10.2 10.10.1 10.10.0 10.9.1 trunk 10.0.0 10.0.1 10.1.0 10.1.1 10.1.2 10.1.3 10.1.4 10.2.0 10.2.1 10.2.2 All 62 releases
acymailing / WpInit / Activation.php

Activation.php in AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress 10.9.1, at WpInit/Activation.php

107 lines 3.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace AcyMailing\WpInit;
4
5 use AcyMailing\Helpers\UpdateHelper;
6
7 class Activation
8 {
9 public function install(): void
10 {
11 $file_name = rtrim(dirname(__DIR__), DS).DS.'back'.DS.'tables.sql';
12 $handle = fopen($file_name, 'r');
13 $queries = fread($handle, filesize($file_name));
14 fclose($handle);
15
16 if (is_multisite() && is_network_admin()) {
17 $currentBlog = get_current_blog_id();
18 $sites = function_exists('get_sites') ? get_sites() : wp_get_sites();
19
20 foreach ($sites as $site) {
21 if (is_object($site)) {
22 $site = get_object_vars($site);
23 }
24 switch_to_blog($site['blog_id']);
25 $this->sampledata($queries);
26 }
27
28 switch_to_blog($currentBlog);
29 } else {
30 $this->sampledata($queries);
31 }
32
33 if (file_exists(ACYM_FOLDER.'update.php')) {
34 unlink(ACYM_FOLDER.'update.php');
35 }
36 }
37
38 private function sampledata(string $queries): void
39 {
40 global $wpdb;
41 $prefix = acym_getPrefix();
42
43 $tableCreationQueries = explode('CREATE TABLE IF NOT EXISTS', str_replace('#__', $prefix, $queries));
44
45 foreach ($tableCreationQueries as $oneTable) {
46 $oneTable = trim($oneTable);
47 if (empty($oneTable)) {
48 continue;
49 }
50
51 $wpdb->query('CREATE TABLE IF NOT EXISTS'.$oneTable);
52 }
53
54 $this->updateAcym();
55 }
56
57 public function updateAcym(): void
58 {
59 if (!in_array(acym_getPrefix().'acym_configuration', acym_getTables(true))) {
60 return;
61 }
62
63 $config = acym_config(true);
64 if (!file_exists(ACYM_FOLDER.'update.php') && $config->get('installcomplete', 0) != 0) {
65 return;
66 }
67
68 acym_increasePerf();
69
70 $updateHelper = new UpdateHelper();
71 $updateHelper->addPref();
72 $updateHelper->updatePref();
73 $updateHelper->updateSQL();
74 $updateHelper->checkDB();
75
76 $config->saveConfig(['downloadurl' => '', 'lastupdatecheck' => '0']);
77
78 $languageFiles = acym_getFiles(ACYM_FOLDER.'language'.DS, '\.ini');
79 acym_createFolder(ACYM_LANGUAGE);
80 acym_createFolder(ACYM_UPLOAD_FOLDER_THUMBNAIL);
81 if (!empty($languageFiles)) {
82 foreach ($languageFiles as $oneFile) {
83 acym_copyFile(ACYM_FOLDER.'language'.DS.$oneFile, ACYM_LANGUAGE.$oneFile);
84 }
85 }
86
87 $updateHelper->installBounceRules();
88 $updateHelper->installList();
89 $updateHelper->installNotifications();
90
91 if ($updateHelper->firstInstallation) {
92 $updateHelper->installTemplates();
93 $updateHelper->installDefaultAutomations();
94 }
95
96 $updateHelper->deleteNewSplashScreenInstall();
97
98 $updateHelper->installFields();
99 $updateHelper->installAddons();
100 $updateHelper->installOverrideEmails();
101
102 $config->saveConfig(['installcomplete' => 1]);
103
104 acym_config(true);
105 }
106 }
107