<commit_before><?php

namespace Spira;

use VanillaConfigurator;
use Composer\Script\Event;

class Build
{
    /**
     * Runs after a composer install.
     *
     * @param   Event   $event  [description]
     * @return  void
     */
    public static function postInstall(Event $event)
    {
        self::getInstance()->buildVanillaApp();
    }

    /**
     * Runs after a composer update.
     *
     * @param   Event   $event  [description]
     * @return  void
     */
    public static function postUpdate(Event $event)
    {
        self::getInstance()->buildVanillaApp();
    }

    /**
     * Runs after a composer update.
     *
     * @param   Event   $event  [description]
     * @return  void
     */
    public static function buildForum(Event $event)
    {
        self::getInstance()->setupVanilla();
    }

    /**
     * Combine the retrieved packages to the required application.
     *
     * @return void
     */
    protected function buildVanillaApp()
    {
        // Copy the main application to public
        $this->recurseCopy('vendor/vanilla/vanilla', 'public');

        // Copy the API module inside the application directory
        $this->recurseCopy('vendor/kasperisager/vanilla-api', 'public/applications/api');

        // Copy the SSO plugin to the plugins directory
        $this->recurseCopy('vendor/vanilla/addons/plugins/jsconnect', 'public/plugins/jsconnect');

        // Copy the initial configuration to conf directory
        copy('config.php', 'public/conf/config.php');

        copy('bootstrap.database.php', 'public/conf/bootstrap.early.php');

        $this->setupVanilla();
    }

    /**
     * Recursively copy a directory structure.
     *
     * @param  string  $source
     * @param  string  $dest
     * @return void
     */
    protected function recurseCopy($source, $dest)
    {
        $dir = opendir($source);
        @mkdir($dest);
        while (false !== ($file = readdir($dir))) {
            if (($file != '.') && ($file != '..')) {
                if (is_dir($source . '/' . $file)) {
                    $this->recurseCopy($source . '/' . $file, $dest . '/' . $file);
                } else {
                    copy($source . '/' . $file, $dest . '/' . $file);
                }
            }
        }
        closedir($dir);
    }

    /**
     * Get an instance of the application builder.
     *
     * @return Build
     */
    protected static function getInstance()
    {
        return new Build;
    }

    /**
     * Run the vanilla setup functions
     */
    protected function setupVanilla()
    {
        (new VanillaConfigurator)->start();
    }
}
<commit_msg>Moved copy config to setup phase so the config is replaced for a repeated migration<commit_after><?php

namespace Spira;

use VanillaConfigurator;
use Composer\Script\Event;

class Build
{
    /**
     * Runs after a composer install.
     *
     * @param   Event   $event  [description]
     * @return  void
     */
    public static function postInstall(Event $event)
    {
        self::getInstance()->buildVanillaApp();
    }

    /**
     * Runs after a composer update.
     *
     * @param   Event   $event  [description]
     * @return  void
     */
    public static function postUpdate(Event $event)
    {
        self::getInstance()->buildVanillaApp();
    }

    /**
     * Runs after a composer update.
     *
     * @param   Event   $event  [description]
     * @return  void
     */
    public static function buildForum(Event $event)
    {
        self::getInstance()->setupVanilla();
    }

    /**
     * Combine the retrieved packages to the required application.
     *
     * @return void
     */
    protected function buildVanillaApp()
    {
        // Copy the main application to public
        $this->recurseCopy('vendor/vanilla/vanilla', 'public');

        // Copy the API module inside the application directory
        $this->recurseCopy('vendor/kasperisager/vanilla-api', 'public/applications/api');

        // Copy the SSO plugin to the plugins directory
        $this->recurseCopy('vendor/vanilla/addons/plugins/jsconnect', 'public/plugins/jsconnect');

        copy('bootstrap.database.php', 'public/conf/bootstrap.early.php');

        $this->setupVanilla();
    }

    /**
     * Recursively copy a directory structure.
     *
     * @param  string  $source
     * @param  string  $dest
     * @return void
     */
    protected function recurseCopy($source, $dest)
    {
        $dir = opendir($source);
        @mkdir($dest);
        while (false !== ($file = readdir($dir))) {
            if (($file != '.') && ($file != '..')) {
                if (is_dir($source . '/' . $file)) {
                    $this->recurseCopy($source . '/' . $file, $dest . '/' . $file);
                } else {
                    copy($source . '/' . $file, $dest . '/' . $file);
                }
            }
        }
        closedir($dir);
    }

    /**
     * Get an instance of the application builder.
     *
     * @return Build
     */
    protected static function getInstance()
    {
        return new Build;
    }

    /**
     * Run the vanilla setup functions
     */
    protected function setupVanilla()
    {

        copy('config.php', 'public/conf/config.php'); //also overwrites the config file for a repeated migration (for qa)

        (new VanillaConfigurator)->start();
    }
}

{'fraction_non_alphanumeric': 0.13427561837455831, 'fraction_numerical': 0.0, 'mean_word_length': 1.8960689283791061, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5253997', 'n_tokens_mistral': 1578, 'n_tokens_neox': 1524, 'n_words': 376}