| @@ -1,23 +1,30 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | namespace AcyMailing\WpInit; |
| 4 | 4 | |
| 5 | +defined('ABSPATH') || die('Restricted Access'); | |
| 6 | + | |
| 5 | 7 | use AcyMailing\Helpers\UpdateHelper; |
| 6 | 8 | |
| 7 | 9 | class Activation |
| 8 | 10 | { |
| 11 | + // Install DB and sample data | |
| 9 | 12 | public function install(): void |
| 10 | 13 | { |
| 11 | 14 | $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 | + $queries = acym_getInternalFileContents($file_name); | |
| 15 | 16 | |
| 17 | + if ($queries === false) { | |
| 18 | + return; | |
| 19 | + } | |
| 20 | + | |
| 21 | + // If it is a network activation (activate on all websites) | |
| 16 | 22 | if (is_multisite() && is_network_admin()) { |
| 17 | 23 | $currentBlog = get_current_blog_id(); |
| 18 | - $sites = function_exists('get_sites') ? get_sites() : wp_get_sites(); | |
| 24 | + $sites = get_sites(); | |
| 19 | 25 | |
| 26 | + // Install on all websites | |
| 20 | 27 | foreach ($sites as $site) { |
| 21 | 28 | if (is_object($site)) { |
| 22 | 29 | $site = get_object_vars($site); |
| 23 | 30 | } |
| @@ -24,8 +31,9 @@ | ||
| 24 | 31 | switch_to_blog($site['blog_id']); |
| 25 | 32 | $this->sampledata($queries); |
| 26 | 33 | } |
| 27 | 34 | |
| 35 | + // Switch back to network main site | |
| 28 | 36 | switch_to_blog($currentBlog); |
| 29 | 37 | } else { |
| 30 | 38 | $this->sampledata($queries); |
| 31 | 39 | } |
| @@ -30,9 +38,9 @@ | ||
| 30 | 38 | $this->sampledata($queries); |
| 31 | 39 | } |
| 32 | 40 | |
| 33 | 41 | if (file_exists(ACYM_FOLDER.'update.php')) { |
| 34 | - unlink(ACYM_FOLDER.'update.php'); | |
| 42 | + acym_deleteFile(ACYM_FOLDER.'update.php'); | |
| 35 | 43 | } |
| 36 | 44 | } |
| 37 | 45 | |
| 38 | 46 | private function sampledata(string $queries): void |
| @@ -47,8 +55,9 @@ | ||
| 47 | 55 | if (empty($oneTable)) { |
| 48 | 56 | continue; |
| 49 | 57 | } |
| 50 | 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. | |
| 51 | 60 | $wpdb->query('CREATE TABLE IF NOT EXISTS'.$oneTable); |
| 52 | 61 | } |
| 53 | 62 | |
| 54 | 63 | $this->updateAcym(); |
| @@ -64,8 +73,9 @@ | ||
| 64 | 73 | if (!file_exists(ACYM_FOLDER.'update.php') && $config->get('installcomplete', 0) != 0) { |
| 65 | 74 | return; |
| 66 | 75 | } |
| 67 | 76 | |
| 77 | + //First we increase the perfs so that we won't have any surprise. | |
| 68 | 78 | acym_increasePerf(); |
| 69 | 79 | |
| 70 | 80 | $updateHelper = new UpdateHelper(); |
| 71 | 81 | $updateHelper->addPref(); |
| @@ -100,7 +110,8 @@ | ||
| 100 | 110 | $updateHelper->installOverrideEmails(); |
| 101 | 111 | |
| 102 | 112 | $config->saveConfig(['installcomplete' => 1]); |
| 103 | 113 | |
| 114 | + // Reload conf | |
| 104 | 115 | acym_config(true); |
| 105 | 116 | } |
| 106 | 117 | } |