Просмотр файла database/upgrades/20200629015654_replace_chars_in_articles.php

Размер файла: 5.01Kb
<?php

use Phinx\Migration\AbstractMigration;

class ReplaceCharsInArticles extends AbstractMigration
{
    /**
     * Migrate Up.
     */
    public function up(): void
    {
        $this->execute("UPDATE articles SET title = replace(`title`, '&amp;', '&')");
        $this->execute("UPDATE articles SET title = replace(`title`, '&quot;', '\"')");
        $this->execute("UPDATE articles SET title = replace(`title`, '&#039;', \"'\")");
        $this->execute("UPDATE articles SET title = replace(`title`, '&#39;', \"'\")");
        $this->execute("UPDATE articles SET title = replace(`title`, '&#36;', '$')");
        $this->execute("UPDATE articles SET title = replace(`title`, '&#92;', '\\\')");
        $this->execute("UPDATE articles SET title = replace(`title`, '&#124;', '|')");
        $this->execute("UPDATE articles SET title = replace(`title`, '&#94;', '^')");
        $this->execute("UPDATE articles SET title = replace(`title`, '&#96;', '`')");
        $this->execute("UPDATE articles SET title = replace(`title`, '&#37;', '%')");
        $this->execute("UPDATE articles SET title = replace(`title`, '&#58;', ':')");
        $this->execute("UPDATE articles SET title = replace(`title`, '&#64;', '@')");
        $this->execute("UPDATE articles SET title = replace(`title`, '&lt;', '<')");
        $this->execute("UPDATE articles SET title = replace(`title`, '&gt;', '>')");

        $this->execute("UPDATE articles SET text = replace(`text`, '&amp;', '&')");
        $this->execute("UPDATE articles SET text = replace(`text`, '&quot;', '\"')");
        $this->execute("UPDATE articles SET text = replace(`text`, '&#039;', \"'\")");
        $this->execute("UPDATE articles SET text = replace(`text`, '&#39;', \"'\")");
        $this->execute("UPDATE articles SET text = replace(`text`, '&#36;', '$')");
        $this->execute("UPDATE articles SET text = replace(`text`, '&#92;', '\\\')");
        $this->execute("UPDATE articles SET text = replace(`text`, '&#124;', '|')");
        $this->execute("UPDATE articles SET text = replace(`text`, '&#94;', '^')");
        $this->execute("UPDATE articles SET text = replace(`text`, '&#96;', '`')");
        $this->execute("UPDATE articles SET text = replace(`text`, '&#37;', '%')");
        $this->execute("UPDATE articles SET text = replace(`text`, '&#58;', ':')");
        $this->execute("UPDATE articles SET text = replace(`text`, '&#64;', '@')");
        $this->execute("UPDATE articles SET text = replace(`text`, '&lt;', '<')");
        $this->execute("UPDATE articles SET text = replace(`text`, '&gt;', '>')");

        $this->execute("UPDATE articles SET tags = replace(`tags`, '&amp;', '&')");
        $this->execute("UPDATE articles SET tags = replace(`tags`, '&quot;', '\"')");
        $this->execute("UPDATE articles SET tags = replace(`tags`, '&#039;', \"'\")");
        $this->execute("UPDATE articles SET tags = replace(`tags`, '&#39;', \"'\")");
        $this->execute("UPDATE articles SET tags = replace(`tags`, '&#36;', '$')");
        $this->execute("UPDATE articles SET tags = replace(`tags`, '&#92;', '\\\')");
        $this->execute("UPDATE articles SET tags = replace(`tags`, '&#124;', '|')");
        $this->execute("UPDATE articles SET tags = replace(`tags`, '&#94;', '^')");
        $this->execute("UPDATE articles SET tags = replace(`tags`, '&#96;', '`')");
        $this->execute("UPDATE articles SET tags = replace(`tags`, '&#37;', '%')");
        $this->execute("UPDATE articles SET tags = replace(`tags`, '&#58;', ':')");
        $this->execute("UPDATE articles SET tags = replace(`tags`, '&#64;', '@')");
        $this->execute("UPDATE articles SET tags = replace(`tags`, '&lt;', '<')");
        $this->execute("UPDATE articles SET tags = replace(`tags`, '&gt;', '>')");
    }

    /**
     * Migrate Down.
     */
    public function down(): void
    {
        $this->execute("UPDATE articles SET title = replace(`title`, '&', '&amp;')");
        $this->execute("UPDATE articles SET title = replace(`title`, '\"', '&quot;')");
        $this->execute("UPDATE articles SET title = replace(`title`, \"'\", '&#039;')");
        $this->execute("UPDATE articles SET title = replace(`title`, '<', '&lt;')");
        $this->execute("UPDATE articles SET title = replace(`title`, '>', '&gt;')");

        $this->execute("UPDATE articles SET text = replace(`text`, '&', '&amp;')");
        $this->execute("UPDATE articles SET text = replace(`text`, '\"', '&quot;')");
        $this->execute("UPDATE articles SET text = replace(`text`, \"'\", '&#039;')");
        $this->execute("UPDATE articles SET text = replace(`text`, '<', '&lt;')");
        $this->execute("UPDATE articles SET text = replace(`text`, '>', '&gt;')");

        $this->execute("UPDATE articles SET tags = replace(`tags`, '&', '&amp;')");
        $this->execute("UPDATE articles SET tags = replace(`tags`, '\"', '&quot;')");
        $this->execute("UPDATE articles SET tags = replace(`tags`, \"'\", '&#039;')");
        $this->execute("UPDATE articles SET tags = replace(`tags`, '<', '&lt;')");
        $this->execute("UPDATE articles SET tags = replace(`tags`, '>', '&gt;')");
    }
}