MOON
Server: Apache
System: Linux res.emeff.ca 3.10.0-962.3.2.lve1.5.24.10.el7.x86_64 #1 SMP Wed Mar 20 07:36:02 EDT 2019 x86_64
User: accemeff (1004)
PHP: 7.0.33
Disabled: NONE
Upload Files
File: /home/accemeff/vendor/craftcms/cms/src/migrations/m170914_204621_asset_cache_shuffle.php
<?php

namespace craft\migrations;

use Craft;
use craft\db\Migration;
use craft\helpers\FileHelper;

/**
 * m170914_204621_asset_cache_shuffle migration.
 */
class m170914_204621_asset_cache_shuffle extends Migration
{
    /**
     * @inheritdoc
     */
    public function safeUp()
    {
        $basePath = Craft::$app->getPath()->getAssetsPath();
        $oldBasePath = $basePath . DIRECTORY_SEPARATOR . 'cache';

        if (!file_exists($oldBasePath)) {
            return;
        }

        foreach (['icons', 'sources'] as $dir) {
            $oldPath = $oldBasePath . DIRECTORY_SEPARATOR . $dir;
            $newPath = $basePath . DIRECTORY_SEPARATOR . $dir;

            if (file_exists($oldPath) && !file_exists($newPath)) {
                rename($oldPath, $newPath);
            }
        }

        // Nuke the entire cache/ folder, including the no-longer-needed cache/resized/
        FileHelper::removeDirectory($oldBasePath);
    }

    /**
     * @inheritdoc
     */
    public function safeDown()
    {
        echo "m170914_204621_asset_cache_shuffle cannot be reverted.\n";
        return false;
    }
}