Roll the cache back to pre-transaction state by comparing the current
cache values with what we planned to set them to.

@param array $old
@param array $new
335385
protected function rollback(array $old, array $new)
    {
        foreach ($old as $key => $value) {
            $current = $this->cache->get($key, $token);

            /*
             * If the value right now equals the one we planned to write, it
             * should be restored to what it was before. If it's yet something
             * else, another process must've stored it and we should leave it
             * alone.
             */
            if ($current === $new) {
                /*
                 * CAS the rollback. If it fails, that means another process
                 * has stored in the meantime and we can just leave it alone.
                 * Note that we can't know the original expiration time!
                 */
                $this->cas($token, $key, $value, 0);
            }
        }

        $this->clear();
    }
529642
public function replaceInFile($old, $new, $append = 0)
    {
        $contents = $this->previous;
        $replaceWith = preg_replace("~$old\n?~", "$new\n", $contents);

        file_put_contents($this->getPath(), $replaceWith, $append);

        return $this;
    }
113421
protected function auditCreatedAttributes(array &$old, array &$new)
    {
        foreach ($this->attributes as $attribute => $value) {
            if ($this->isAttributeAuditable($attribute)) {
                $new[$attribute] = $value;
            }
        }
    }
1006521
public function rename($old, $new)
    {
        return ($this->isConnected() === true) ? ftp_rename($this->getConnection(), $old, $new) : false;
    }
972891
public function mergeAttributes( $old, $new ) {
		$attributes = [
			'methods' => $this->mergeMethodsAttribute(
				(array) Arr::get( $old, 'methods', [] ),
				(array) Arr::get( $new, 'methods', [] )
			),

			'condition' => $this->mergeConditionAttribute(
				Arr::get( $old, 'condition', null ),
				Arr::get( $new, 'condition', null )
			),

			'middleware' => $this->mergeMiddlewareAttribute(
				(array) Arr::get( $old, 'middleware', [] ),
				(array) Arr::get( $new, 'middleware', [] )
			),

			'namespace' => $this->mergeNamespaceAttribute(
				Arr::get( $old, 'namespace', '' ),
				Arr::get( $new, 'namespace', '' )
			),

			'handler' => $this->mergeHandlerAttribute(
				Arr::get( $old, 'handler', '' ),
				Arr::get( $new, 'handler', '' )
			),

			'query' => $this->mergeQueryAttribute(
				Arr::get( $old, 'query', null ),
				Arr::get( $new, 'query', null )
			),
		];

		return $attributes;
	}
679097
public function renameTable($old, $new)
    {
        $this->replaceText("`$old`", "`$new`");
        $this->replaceText("\"$old\"", "\"$new\"");
        $this->replaceText(Convert::symbol2sql($old), Convert::symbol2sql($new));
    }
106403
private function diffRecords($old, $new)
	{
		$diff = Set::diff($old, $new);
		$formatted = array();

		foreach ($diff as $key => $value) {
			if (!isset($old[$key]) || !isset($new[$key])) {
				continue;
			}

			$formatted[$key] = array('old' => $old[$key], 'new' => $new[$key]);
		}

		return $formatted;
	}
1042424
protected function getForeignKeysMigrations($new = [], $old = [])
    {
        if (empty($new['tables'])) {
            return [];
        }
        $output = [];
        foreach ($new['tables'] as $tableId => $newTable) {
            if ($newTable['table']['table_name'] === $this->options['default_migration_table']) {
                continue;
            }
            $oldTable = $old['tables'][$tableId];

            if (!empty($oldTable['foreign_keys'])) {
                foreach ($oldTable['foreign_keys'] as $fkName => $fkData) {
                    if (!isset($newTable['foreign_keys'][$fkName])) {
                        $output[] = $this->getForeignKeyRemove($tableId, $fkName);
                    }
                }
            }
            if (!empty($newTable['foreign_keys'])) {
                foreach ($newTable['foreign_keys'] as $fkName => $fkData) {
                    if (!isset($oldTable['foreign_keys'][$fkName])) {
                        $output[] = $this->getForeignKeyCreate($tableId, $fkName);
                    }
                }
            }
        }

        return $output;
    }
1362288
public function handle($old, $new)
    {
        if ( ! $this->canHandle($old) || ! $this->canHandle($new)) {
            return null;
        }

        if (((string) $new->getReturnType())) {
            return false;
        }

        if (((string) $new->getReturnType()) == ((string) $old->getReturnType())) {
            return false;
        }

        $this->lastException = new FailedConstraint(
            sprintf(
                '%s::%s() return type "%s" were removed',
                $old->getAttribute('parent')->namespacedName,
                $old->name,
                $old->getReturnType(),
                $new->getReturnType()
            )
        );

        return true;
    }
530890
public function renameTable($old, $new)
    {
        $this->append(sprintf('RENAME TABLE %s TO %s ', $this->quote($old), $this->quote($new)));
        return $this;
    }
530836
protected function merge(array $old, array $new)
    {
        foreach ($new as $key => $value) {
            if (isset($old[$key]) && is_array($old[$key]) && is_array($value)) {
                $old[$key] = $this->merge($old[$key], $value);
            } else {
                $old[$key] = $value;
            }
        }

        return $old;
    }
799974
protected function auditDeletedAttributes(array &$old, array &$new)
    {
        foreach ($this->attributes as $attribute => $value) {
            if ($this->isAttributeAuditable($attribute)) {
                $old[$attribute] = $value;
            }
        }
    }
519666
private function buildDiffTable(Text $old, Text $new) {
        $diffTable = [array_fill(0, count($new) + 1, 0)];
        for ($row = 1; $row <= count($old); $row++) {
            $diffTable[$row] = [0];
            for ($col = 1; $col <= count($new); $col++) {
                $diffTable[$row][$col] = $old[$row - 1] === $new[$col - 1]
                    ? $diffTable[$row - 1][$col - 1] + 1
                    : max($diffTable[$row - 1][$col], $diffTable[$row][$col - 1]);
            }
        }

        return $diffTable;
    }
650964
protected function addChangeMethod($output, $new, $old): array
    {
        $output[] = $this->ind . 'public function change()';
        $output[] = $this->ind . '{';

        if (!empty($this->options['foreign_keys'])) {
            $output[] = $this->getSetUniqueChecks(0);
            $output[] = $this->getSetForeignKeyCheck(0);
        }

        $output = $this->getTableMigrationNewDatabase($output, $new, $old);
        $output = $this->getTableMigrationTables($output, $new, $old);

        if (!empty($this->options['foreign_keys'])) {
            $output[] = $this->getSetForeignKeyCheck(1);
            $output[] = $this->getSetUniqueChecks(1);
        }

        $output[] = $this->ind . '}';

        return $output;
    }
1216336
public function cas($key, $old_value, $new_value)
    {
        $connection = $this->getConnection($key);
        $this->writeToRemote(array(
            'cmd' => 'cas',
            'md5' => md5(serialize($old_value)),
            'key' => $key,
            'value' => $new_value,
        ), $connection);
        return $this->readFromRemote($connection);
    }
550270
public function replace(string $old, string $new)
    {
        if ($old === $new) {
            return;
        }
        $this->tokenize();
        $i = array_search($old, $this->tokens);
        if ($i !== false) {
            $j = array_search($new, $this->tokens);
            if ($j === false) {
                $this->tokens[$i] = $new;
            } else {
                array_splice($this->tokens, $i, 1);
            }
            $this->setAttributeValue();
        }
    }
554706
static public function setCache( $value )
	{
		$old = self::$cache;
		self::$cache = (boolean) $value;

		return $old;
	}