# acymailing/11.0.4/WpInit/Activation.php

AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress, version 11.0.4. 118 lines.

- Page: https://pluginprobe.com/plugins/acymailing/11.0.4/code/WpInit/Activation.php
- Raw: https://pluginprobe.com/plugins/acymailing/11.0.4/raw/WpInit/Activation.php
- Modified: 2026-08-03T10:18:54+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/acymailing/11.0.4/code/WpInit/Activation.php#L10-L20`.

```php
<?php

namespace AcyMailing\WpInit;

defined('ABSPATH') || die('Restricted Access');

use AcyMailing\Helpers\UpdateHelper;

class Activation
{
    // Install DB and sample data
    public function install(): void
    {
        $file_name = rtrim(dirname(__DIR__), DS).DS.'back'.DS.'tables.sql';
        $queries = acym_getInternalFileContents($file_name);

        if ($queries === false) {
            return;
        }

        // If it is a network activation (activate on all websites)
        if (is_multisite() && is_network_admin()) {
            $currentBlog = get_current_blog_id();
            $sites = get_sites();

            // Install on all websites
            foreach ($sites as $site) {
                if (is_object($site)) {
                    $site = get_object_vars($site);
                }
                switch_to_blog($site['blog_id']);
                $this->sampledata($queries);
            }

            // Switch back to network main site
            switch_to_blog($currentBlog);
        } else {
            $this->sampledata($queries);
        }

        if (file_exists(ACYM_FOLDER.'update.php')) {
            acym_deleteFile(ACYM_FOLDER.'update.php');
        }
    }

    private function sampledata(string $queries): void
    {
        global $wpdb;
        $prefix = acym_getPrefix();

        $tableCreationQueries = explode('CREATE TABLE IF NOT EXISTS', str_replace('#__', $prefix, $queries));

        foreach ($tableCreationQueries as $oneTable) {
            $oneTable = trim($oneTable);
            if (empty($oneTable)) {
                continue;
            }

            // 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.
            $wpdb->query('CREATE TABLE IF NOT EXISTS'.$oneTable);
        }

        $this->updateAcym();
    }

    public function updateAcym(): void
    {
        if (!in_array(acym_getPrefix().'acym_configuration', acym_getTables(true))) {
            return;
        }

        $config = acym_config(true);
        if (!file_exists(ACYM_FOLDER.'update.php') && $config->get('installcomplete', 0) != 0) {
            return;
        }

        //First we increase the perfs so that we won't have any surprise.
        acym_increasePerf();

        $updateHelper = new UpdateHelper();
        $updateHelper->addPref();
        $updateHelper->updatePref();
        $updateHelper->updateSQL();
        $updateHelper->checkDB();

        $config->saveConfig(['downloadurl' => '', 'lastupdatecheck' => '0']);

        $languageFiles = acym_getFiles(ACYM_FOLDER.'language'.DS, '\.ini');
        acym_createFolder(ACYM_LANGUAGE);
        acym_createFolder(ACYM_UPLOAD_FOLDER_THUMBNAIL);
        if (!empty($languageFiles)) {
            foreach ($languageFiles as $oneFile) {
                acym_copyFile(ACYM_FOLDER.'language'.DS.$oneFile, ACYM_LANGUAGE.$oneFile);
            }
        }

        $updateHelper->installBounceRules();
        $updateHelper->installList();
        $updateHelper->installNotifications();

        if ($updateHelper->firstInstallation) {
            $updateHelper->installTemplates();
            $updateHelper->installDefaultAutomations();
        }

        $updateHelper->deleteNewSplashScreenInstall();

        $updateHelper->installFields();
        $updateHelper->installAddons();
        $updateHelper->installOverrideEmails();

        $config->saveConfig(['installcomplete' => 1]);

        // Reload conf
        acym_config(true);
    }
}

```
