2

Anyone successfully convert MH file fieldtype that has multiple images to a matrix or similar? I have some entries that have multiple images tied to a single MH file field. I'm in the process of upgrading EE1 to EE2, and fields with just one image are fine, but entries with multiple images have data stored like:

image_1.jpg
image_2.jpg

I've seen these threads for after upgrading to EE2 for nGen file field and MH file field, but these are specific to single files.

3

All credit goes to Brandon. I searched and found this thread last night which was ultimately the solution. I'll post the script below as that thread was a little confusing to follow until they got it working.

You'll need to convert all MH File fields to a Matrix field first. Then run the script below.

Make sure to replace XX with your Matrix field ID, YY with your File column ID, and ZZ with your file upload directory ID.

<?php

    // Converts Mark Huot's File Field with multiple images to a Matrix column
    mysql_connect("localhost", "db_username", "db_password") or die(mysql_error());
    mysql_select_db("database_name") or die(mysql_error());

    $query = mysql_query('SELECT site_id, entry_id, field_id_XX FROM exp_channel_data WHERE field_id_XX IS NOT NULL');
    while ($row = mysql_fetch_assoc($query)) {

        // get the file names
        $files = array_filter(preg_split('/[\r\n]/', $row['field_id_XX']));

        // add them to exp_matrix_data
        foreach ($files as $i => $file) {

            mysql_query('INSERT INTO exp_matrix_data (site_id, entry_id, field_id, row_order, col_id_YY)
            VALUES ('.$row['site_id'].', '.$row['entry_id'].', XX, '.$i.', "{filedir_ZZ}'.$file.'")');
        }
    }
?>
2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.