<commit_before><?php

namespace AlphaLemon\Block\BusinessCarouselBundle\Core\Listener; 

use AlphaLemon\BootstrapBundle\Core\Event\PackageInstalledEvent;
use AlphaLemon\BootstrapBundle\Core\Event\PackageUninstalledEvent;
use AlphaLemon\PageTreeBundle\Core\Tools\AlToolkit;
use AlphaLemon\AlphaLemonCmsBundle\Core\Model\AlBlockQuery;

/**
 * Executes some actions when a package is installed or uninstalled
 */
class SetupListener 
{
    private $queries = array('DROP TABLE al_app_business_carousel;',);
    
    /**
     * The action performed when the BusinessCarousel package is installed
     * 
     * @param PackageInstalledEvent $event 
     */
    public function onPackageInstalled(PackageInstalledEvent $event)
    {
        $container = $event->getContainer();
        $connection = $this->getPropelConnection($container);
        
        // Sets phing include path
        set_include_path($container->getParameter('kernel.root_dir').'/..'.PATH_SEPARATOR.$container->getParameter('propel.phing_path').'/classes'.PATH_SEPARATOR.get_include_path());
        
        // Builds the sql
        AlToolkit::executeCommand($container->get('kernel'), 'propel:build-sql');        
        
        // Retrieves the CREATE TABLE for the al_app_business_carousel table
        $sqlFile = $container->getParameter('kernel.root_dir') . DIRECTORY_SEPARATOR . 'propel' . DIRECTORY_SEPARATOR . 'sql' . DIRECTORY_SEPARATOR . $this->connectionName . '.sql';
        $sql = file_get_contents($sqlFile);
        preg_match('/CREATE TABLE `al_app_business_carousel[^;]+/s', $sql, $match);
        if (!empty($match)) {
            $this->queries[] = $match[0];
        } else {
            $this->queries[] =  'CREATE TABLE IF NOT EXISTS `al_app_business_carousel` (
                                  `id` int(11) NOT NULL AUTO_INCREMENT,
                                  `block_id` int(11) NOT NULL,
                                  `name` varchar(128) DEFAULT NULL,
                                  `surname` varchar(128) DEFAULT NULL,
                                  `role` varchar(128) DEFAULT NULL,
                                  `content` text NOT NULL,
                                  PRIMARY KEY (`id`),
                                  KEY `I_BLOCK` (`block_id`)
                                ) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;';
        }
        
        $this->executeQueries($connection, $this->queries);
        
        // Builds the model
        AlToolkit::executeCommand($container->get('kernel'), 'propel:build-model');
    }

    /**
     * The action performed when the BusinessCarousel package is uninstalled
     * 
     * @param PackageUninstalledEvent $event 
     */
    public function onPackageUninstalled(PackageUninstalledEvent $event)
    {
        // Removes the BusinessCarousel blocks
        AlBlockQuery::create()->filterByClassName('BusinessCarousel')->delete();
        
        // Removes the al_app_business_carousel table
        $container = $event->getContainer();
        $connection = $this->getPropelConnection($container);<commit_msg>fixed the setup listener<commit_after><?php

namespace AlphaLemon\Block\BusinessCarouselBundle\Core\Listener; 

use AlphaLemon\BootstrapBundle\Core\Event\PackageInstalledEvent;
use AlphaLemon\BootstrapBundle\Core\Event\PackageUninstalledEvent;
use AlphaLemon\PageTreeBundle\Core\Tools\AlToolkit;
use AlphaLemon\AlphaLemonCmsBundle\Core\Model\AlBlockQuery;

/**
 * Executes some actions when a package is installed or uninstalled
 */
class SetupListener 
{
    private $queries = array('DROP TABLE al_app_business_carousel;',);
    
    /**
     * The action performed when the BusinessCarousel package is installed
     * 
     * @param PackageInstalledEvent $event 
     */
    public function onPackageInstalled(PackageInstalledEvent $event)
    {
        $container = $event->getContainer();
        if ($container->has('propel.configuration')) {
            ob_start();
            $connection = $this->getPropelConnection($container);

            // Sets phing include path
            set_include_path($container->getParameter('kernel.root_dir').'/..'.PATH_SEPARATOR.$container->getParameter('propel.phing_path').'/classes'.PATH_SEPARATOR.get_include_path());

            // Builds the sql
            AlToolkit::executeCommand($container->get('kernel'), 'propel:build-sql');        

            // Retrieves the CREATE TABLE for the al_app_business_carousel table
            $sqlFile = $container->getParameter('kernel.root_dir') . DIRECTORY_SEPARATOR . 'propel' . DIRECTORY_SEPARATOR . 'sql' . DIRECTORY_SEPARATOR . $this->connectionName . '.sql';
            $sql = file_get_contents($sqlFile);
            preg_match('/CREATE TABLE `al_app_business_carousel[^;]+/s', $sql, $match);
            if (!empty($match)) {
                $this->queries[] = $match[0];
            } else {
                $this->queries[] =  'CREATE TABLE IF NOT EXISTS `al_app_business_carousel` (
                                      `id` int(11) NOT NULL AUTO_INCREMENT,
                                      `block_id` int(11) NOT NULL,
                                      `name` varchar(128) DEFAULT NULL,
                                      `surname` varchar(128) DEFAULT NULL,
                                      `role` varchar(128) DEFAULT NULL,
                                      `content` text NOT NULL,
                                      PRIMARY KEY (`id`),
                                      KEY `I_BLOCK` (`block_id`)
                                    ) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;';
            }

            $this->executeQueries($connection, $this->queries);

            // Builds the model
            AlToolkit::executeCommand($container->get('kernel'), 'propel:build-model');
            
            // Executes silently its job
            ob_end_clean();
            
            $event->setSuccess(true);
        }
        
        return $event;
    }

    /**
     * The action performed when the BusinessCarousel package is uninstalled
     * 
     * @param PackageUninstalledEvent $event 
     */
    public function onPackageUninstalled(PackageUninstalledEvent $event)
    {
        // Removes the BusinessCarousel blocks
        AlBlockQuery::create()->filterByClassName('BusinessCarousel')->delete();
        
        // Removes the al_app_business_carousel table
        $container = $event->getContainer();
        $connection = $this->getPropelConnection($container);
{'fraction_non_alphanumeric': 0.10899099374141352, 'fraction_numerical': 0.00488475041978324, 'mean_word_length': 2.1652173913043478, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 37, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 20, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7564995', 'n_tokens_mistral': 1822, 'n_tokens_neox': 1722, 'n_words': 343}