<commit_before><?php
/*
 * This file is part of the Magallanes package.
*
* (c) <NAME> <<EMAIL>>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Mage\Task\BuiltIn\Releases;

use Mage\Console;
use Mage\Task\Factory;
use Mage\Task\AbstractTask;
use Mage\Task\Releases\IsReleaseAware;
use Mage\Task\Releases\RollbackAware;

/**
 * Task for Performing a Rollback Operation
 *
 * @author <NAME> <<EMAIL>>
 */
class RollbackTask extends AbstractTask implements IsReleaseAware
{
    /**
     * (non-PHPdoc)
     * @see \Mage\Task\AbstractTask::getName()
     */
    public function getName()
    {
        return 'Rollback release [built-in]';
    }

    /**
     * Gets the Release ID to Rollback To
     * @return integer
     */
    public function getReleaseId()
    {
        return $this->getConfig()->getReleaseId();
    }

    /**
     * Performs a Rollback Operation
     * @see \Mage\Task\AbstractTask::run()
     */
    public function run()
    {
        if ($this->getConfig()->release('enabled', false) === true) {
            $releasesDirectory = $this->getConfig()->release('directory', 'releases');
            $symlink = $this->getConfig()->release('symlink', 'current');

            $output = '';
            $result = $this->runCommandRemote('ls -1 ' . $releasesDirectory, $output);
            $releases = ($output == '') ? array() : explode(PHP_EOL, $output);

            $inDeploy = $this->getParameter('inDeploy',false);

            if (count($releases) == 0) {
                Console::output('Release are not available for <bold>' . $this->getConfig()->getHost() . '</bold> ... <red>FAIL</red>');

            } else {
                rsort($releases);
                $deleteCurrent = $this->getConfig()->getParameter('deleteCurrent',
                    $this->getConfig()->deployment('delete-on-rollback',
                        $this->getConfig()->general('delete-on-rollback',false)
                    )
                );

                $releaseIsAvailable = false;
                if ($this->getReleaseId() == '') {
                    $releaseId = $releases[0];
                    $releaseIsAvailable = true;

                } else if ($this->getReleaseId() <= 0) {
                    $index = $this->getReleaseId() * -1;
                    if (isset($releases[$index])) {
                        $releaseId = $releases[$index];
                        $releaseIsAvailable = true;
                    }
                } else {
                    if (in_array($this->getReleaseId(), $releases)) {
                        $releaseId = $this->getReleaseId();<commit_msg>Rollback directory should include deployment:to config variable<commit_after><?php
/*
 * This file is part of the Magallanes package.
*
* (c) <NAME> <<EMAIL>>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Mage\Task\BuiltIn\Releases;

use Mage\Console;
use Mage\Task\Factory;
use Mage\Task\AbstractTask;
use Mage\Task\Releases\IsReleaseAware;
use Mage\Task\Releases\RollbackAware;

/**
 * Task for Performing a Rollback Operation
 *
 * @author <NAME> <<EMAIL>>
 */
class RollbackTask extends AbstractTask implements IsReleaseAware
{
    /**
     * (non-PHPdoc)
     * @see \Mage\Task\AbstractTask::getName()
     */
    public function getName()
    {
        return 'Rollback release [built-in]';
    }

    /**
     * Gets the Release ID to Rollback To
     * @return integer
     */
    public function getReleaseId()
    {
        return $this->getConfig()->getReleaseId();
    }

    /**
     * Performs a Rollback Operation
     * @see \Mage\Task\AbstractTask::run()
     */
    public function run()
    {
        if ($this->getConfig()->release('enabled', false) === true) {
            $releasesDirectory = $this->getConfig()->release('directory', 'releases');
            $symlink = $this->getConfig()->release('symlink', 'current');

            if (substr($symlink, 0, 1) == '/') {
                $releasesDirectory = rtrim($this->getConfig()->deployment('to'), '/') . '/' . $releasesDirectory;
            }

            $output = '';
            $result = $this->runCommandRemote('ls -1 ' . $releasesDirectory, $output);
            $releases = ($output == '') ? array() : explode(PHP_EOL, $output);

            $inDeploy = $this->getParameter('inDeploy',false);

            if (count($releases) == 0) {
                Console::output('Release are not available for <bold>' . $this->getConfig()->getHost() . '</bold> ... <red>FAIL</red>');

            } else {
                rsort($releases);
                $deleteCurrent = $this->getConfig()->getParameter('deleteCurrent',
                    $this->getConfig()->deployment('delete-on-rollback',
                        $this->getConfig()->general('delete-on-rollback',false)
                    )
                );

                $releaseIsAvailable = false;
                if ($this->getReleaseId() == '') {
                    $releaseId = $releases[0];
                    $releaseIsAvailable = true;

                } else if ($this->getReleaseId() <= 0) {
                    $index = $this->getReleaseId() * -1;
                    if (isset($releases[$index])) {
                        $releaseId = $releases[$index];
                        $releaseIsAvailable = true;
                    }
                } else {
                    if (in_array($this->getReleaseId(), $releases)) {
                        $releaseId = $this->getReleaseId();
{'fraction_non_alphanumeric': 0.15227434257285002, 'fraction_numerical': 0.0021321961620469083, 'mean_word_length': 1.9673168160253032, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 71, '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': '2968208', 'n_tokens_mistral': 1615, 'n_tokens_neox': 1496, 'n_words': 330}