HEX
Server: Apache
System: Linux server1.ariadata.co 4.18.0-553.120.1.el8_10.x86_64 #1 SMP Mon Apr 20 18:04:27 EDT 2026 x86_64
User: nepi (1051)
PHP: 7.4.33
Disabled: exec,passthru,shell_exec,system,show_source,popen,proc_open
Upload Files
File: /home/nepi/www/migrations/upgrades/20191202164206_update_directus_files.php
<?php

use Phinx\Migration\AbstractMigration;
use function Directus\get_random_string;

class UpdateDirectusFiles extends AbstractMigration
{
  public function change() {
    $filesTable = $this->table('directus_files');

    // -------------------------------------------------------------------------
    // Rename filename to filename_disk
    // -------------------------------------------------------------------------
    if ($filesTable->hasColumn('filename')) {
        $filesTable->renameColumn('filename', 'filename_disk');
    }

    // -------------------------------------------------------------------------
    // Add filename_download column
    // -------------------------------------------------------------------------
    if ($filesTable->hasColumn('filename_download') == false) {
        $filesTable->addColumn('filename_download', 'string', [
            'limit' => 255,
            'null' => false
        ]);
    }

    // -------------------------------------------------------------------------
    // Add private hash column
    // -------------------------------------------------------------------------
    if ($filesTable->hasColumn('private_hash') == false) {
        $filesTable->addColumn('private_hash', 'string', [
            'limit' => 16,
            'null' => true,
            'default' => null
        ]);
    }

    // -------------------------------------------------------------------------
    // Add a private hash for all existing files
    // -------------------------------------------------------------------------
    $filesTable->save(); // Make sure the private hash column above is saved

    $filesWithoutPrivateHash = $this->fetchAll('SELECT id FROM directus_files WHERE private_hash = null;');

    foreach($filesWithoutPrivateHash as $key => $value) {
        $this->execute(\Directus\phinx_update(
            $this->getAdapter(),
            'directus_files',
            ['private_hash' => get_random_string()],
            ['id' => $value['id']]
        ));
    }

    // -------------------------------------------------------------------------
    // Save changes to table
    // -------------------------------------------------------------------------
    $filesTable->save();
  }
}