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/20191203105400_add_hash_filedownload_if_empty.php
<?php

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

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

    // -------------------------------------------------------------------------
    // Add a private hash for all existing files
    // -------------------------------------------------------------------------
    $filesWithoutPrivateHash = $this->fetchAll('SELECT id FROM directus_files WHERE private_hash IS NULL OR private_hash = "";');

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

    // -------------------------------------------------------------------------
    // Add a private hash for all existing files
    // -------------------------------------------------------------------------
    $filesWithoutFiledownload = $this->fetchAll('SELECT id, filename_disk FROM directus_files WHERE filename_download IS NULL OR filename_download = "";');

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

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