Legacy Exporting 5.6 to 5.8

I am exporting an old website from 5.6 to 5.8. I am running into an issue that ive never rain into before. The majority of files are not exporting. I can see the ones exporting have “/index.php/download_file/view_inline/” in the content, but the ones that dont have “{CCM:BASE_URL}/files/5515/2229/1937/image.png”. i have 700 files in the File Manager with sets and descriptions attached. is there something i can do to convert the offending code to the inline link so that the files export properly.

Unfortunately the migration tool only exports files that are used by the content block.

You will have to modify the routine responsible to include the other ones.

It’s not super complicated, I did it in the past. Personally I exported normally and then modified the code to revert the selection and export only the ones not already exported.

I would be interested in the code if you would be willing to share.

What I did is I modified the file controllers\dashboard\migration\export.php in the migration tool.

There’s a method named download_files()

I created a new method called download_files_missing() in the same file.

public function download_files_missing()
{
    @ini_set('memory_limit', '-1');
    @set_time_limit(0);
    $id = $_POST['id'];
    if ($id) {
        $batch = MigrationBatch::getByID($id);
    }
    if (!is_object($batch)) {
        $this->error->add(t('Invalid Batch'));
    }
    if (!$this->token->validate('download_files')) {
        $this->error->add($this->token->getErrorMessage());
    }
    $fh = Loader::helper('file');
    $vh = Loader::helper('validation/identifier');

    if (!$this->error->has()) {
        $temp = sys_get_temp_dir();
        if (!$temp) {
            $temp = $fh->getTemporaryDirectory();
        }
        $filename = $temp.'/'.$vh->getString().'.zip';
        $files = array();
        $prefixes = array();
        Loader::model('file_list');
        $fileList = new FileList();
        $fmFiles = $fileList->get();
        $batchFID = (array) $_POST['batchFileID'];

        foreach ($fmFiles as $f) {
        // foreach ((array) $_POST['batchFileID'] as $fID) {
            if ($f->isError()) {
                continue;
            }
            if (in_array($f->getFileID(), $batchFID)) {
                continue;
            }

            // $fp = new Permissions($f);
            // if ($fp->canRead()) {
                if (!in_array($f->getPath(), $files) && file_exists($f->getPath())) {
                    $files[] = $f->getPath();
                    $prefixes[] = $f->getPrefix();
                }
            // }
        }
        if (empty($files)) {
            throw new Exception(t('None of the requested files could be found.'));
        }
        if (class_exists('ZipArchive', false)) {
            $zip = new ZipArchive();
            $res = $zip->open($filename, ZipArchive::CREATE);
            if ($res !== true) {
                throw new Exception(t('Could not open with ZipArchive::CREATE'));
            }
            for ($i = 0; $i < count($files); $i++) {
                $f = $files[$i];
                $prefix = $prefixes[$i];
                $zip->addFile($f, $prefix . '_' . basename($f));
            }
            $zip->close();
        } else {
            throw new \Exception(t('ZipArchive extension required.'));
        }
        $fh->forceDownload($filename);
    }
    exit;
}

So first you would export your files normally. Then you would use this new method to export the other files. The method would export only files that were not already exported using the normal method.

To do so you would modify the file single_pages\dashboard\migration\export.php
Look for the line:

<form method="post" action="<?=View::url('/dashboard/migration/export', 'download_files')?>">

and modify it to use the new method name like so:

<form method="post" action="<?=View::url('/dashboard/migration/export', 'download_files_missing')?>">

Then on the page where you export the files (reload it) select all the files listed (the ones already exported) and click on the button to export. It will export all the other files that are not in the list.

Make sure you select all the files on the page to exclude them from the modified export, so the same file doesn’t get exported twice.

Technically, you could forego exporting the files normally first and just use my modified method directly. You would do it without checking any of the files in the list, and the resulting file would contain absolutely all the files.

But by doing it the other way, you can still make sure you know which files are required by core blocks and which are only required by third-party blocks.

2 Likes

This is much cleaner than my solution. I added 2 steps. 1 getting the array of files from the File Manager search results, then adding those files to the BatchExporter. Not ideal, but it worked. I then exported the File sets and the FileSetFiles to the new location. crossing all my t’s and dotting my i’s. Thanks.