| 1 |
<?php |
| 2 |
|
| 3 |
namespace AcyMailing\WpInit; |
| 4 |
|
| 5 |
defined('ABSPATH') || die('Restricted Access'); |
| 6 |
|
| 7 |
use AcyMailing\Helpers\UpdateHelper; |
| 8 |
|
| 9 |
class Activation |
| 10 |
{ |
| 11 |
// Install DB and sample data |
| 12 |
public function install(): void |
| 13 |
{ |
| 14 |
$file_name = rtrim(dirname(__DIR__), DS).DS.'back'.DS.'tables.sql'; |
| 15 |
$queries = acym_getInternalFileContents($file_name); |
| 16 |
|
| 17 |
if ($queries === false) { |
| 18 |
return; |
| 19 |
} |
| 20 |
|
| 21 |
// If it is a network activation (activate on all websites) |
| 22 |
if (is_multisite() && is_network_admin()) { |
| 23 |
$currentBlog = get_current_blog_id(); |
| 24 |
$sites = get_sites(); |
| 25 |
|
| 26 |
// Install on all websites |
| 27 |
foreach ($sites as $site) { |
| 28 |
if (is_object($site)) { |
| 29 |
$site = get_object_vars($site); |
| 30 |
} |
| 31 |
switch_to_blog($site['blog_id']); |
| 32 |
$this->sampledata($queries); |
| 33 |
} |
| 34 |
|
| 35 |
// Switch back to network main site |
| 36 |
switch_to_blog($currentBlog); |
| 37 |
} else { |
| 38 |
$this->sampledata($queries); |
| 39 |
} |
| 40 |
|
| 41 |
if (file_exists(ACYM_FOLDER.'update.php')) { |
| 42 |
acym_deleteFile(ACYM_FOLDER.'update.php'); |
| 43 |
} |
| 44 |
} |
| 45 |
|
| 46 |
private function sampledata(string $queries): void |
| 47 |
{ |
| 48 |
global $wpdb; |
| 49 |
$prefix = acym_getPrefix(); |
| 50 |
|
| 51 |
$tableCreationQueries = explode('CREATE TABLE IF NOT EXISTS', str_replace('#__', $prefix, $queries)); |
| 52 |
|
| 53 |
foreach ($tableCreationQueries as $oneTable) { |
| 54 |
$oneTable = trim($oneTable); |
| 55 |
if (empty($oneTable)) { |
| 56 |
continue; |
| 57 |
} |
| 58 |
|
| 59 |
// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.DirectDatabaseQuery.SchemaChange, WordPress.DB.PreparedSQL.NotPrepared, PluginCheck.Security.DirectDB.UnescapedDBParameter -- DDL schema creation during plugin install, caching and abstraction are not applicable here. |
| 60 |
$wpdb->query('CREATE TABLE IF NOT EXISTS'.$oneTable); |
| 61 |
} |
| 62 |
|
| 63 |
$this->updateAcym(); |
| 64 |
} |
| 65 |
|
| 66 |
public function updateAcym(): void |
| 67 |
{ |
| 68 |
if (!in_array(acym_getPrefix().'acym_configuration', acym_getTables(true))) { |
| 69 |
return; |
| 70 |
} |
| 71 |
|
| 72 |
$config = acym_config(true); |
| 73 |
if (!file_exists(ACYM_FOLDER.'update.php') && $config->get('installcomplete', 0) != 0) { |
| 74 |
return; |
| 75 |
} |
| 76 |
|
| 77 |
//First we increase the perfs so that we won't have any surprise. |
| 78 |
acym_increasePerf(); |
| 79 |
|
| 80 |
$updateHelper = new UpdateHelper(); |
| 81 |
$updateHelper->addPref(); |
| 82 |
$updateHelper->updatePref(); |
| 83 |
$updateHelper->updateSQL(); |
| 84 |
$updateHelper->checkDB(); |
| 85 |
|
| 86 |
$config->saveConfig(['downloadurl' => '', 'lastupdatecheck' => '0']); |
| 87 |
|
| 88 |
$languageFiles = acym_getFiles(ACYM_FOLDER.'language'.DS, '\.ini'); |
| 89 |
acym_createFolder(ACYM_LANGUAGE); |
| 90 |
acym_createFolder(ACYM_UPLOAD_FOLDER_THUMBNAIL); |
| 91 |
if (!empty($languageFiles)) { |
| 92 |
foreach ($languageFiles as $oneFile) { |
| 93 |
acym_copyFile(ACYM_FOLDER.'language'.DS.$oneFile, ACYM_LANGUAGE.$oneFile); |
| 94 |
} |
| 95 |
} |
| 96 |
|
| 97 |
$updateHelper->installBounceRules(); |
| 98 |
$updateHelper->installList(); |
| 99 |
$updateHelper->installNotifications(); |
| 100 |
|
| 101 |
if ($updateHelper->firstInstallation) { |
| 102 |
$updateHelper->installTemplates(); |
| 103 |
$updateHelper->installDefaultAutomations(); |
| 104 |
} |
| 105 |
|
| 106 |
$updateHelper->deleteNewSplashScreenInstall(); |
| 107 |
|
| 108 |
$updateHelper->installFields(); |
| 109 |
$updateHelper->installAddons(); |
| 110 |
$updateHelper->installOverrideEmails(); |
| 111 |
|
| 112 |
$config->saveConfig(['installcomplete' => 1]); |
| 113 |
|
| 114 |
// Reload conf |
| 115 |
acym_config(true); |
| 116 |
} |
| 117 |
} |
| 118 |
|