Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ExpressionEngine 1 to ExpressionEngine 2 Upgrade with nGen File Field

I'm about to do an ExpressionEngine v1 to ExpressionEngine v2 Upgrade with lots of data stored in nGen File Fields.

What are the steps I need to take pre and post upgrade to get this data working correctly with the EE2 SafeCracker File field?

like image 220
Anna_MediaGirl Avatar asked Oct 24 '12 00:10

Anna_MediaGirl


3 Answers

After upgrading to EE2, find each ex-nGen File field and change its Field Type to File, and run this SQL query:

UPDATE exp_channel_data
SET field_id_X = CONCAT('{filedir_Y}', field_id_X)
WHERE field_id_X != ''
AND field_id_X NOT LIKE '{filedir_%'

Replace “X” with your File field’s ID (you can get that from exp_channel_fields), and Y with the upload preference ID that nGen File Field was set to.

If you had Matrix installed in EE1, upgrade to Matrix 2/EE2 and do the same for any ex-nGen File columns, using this SQL query instead:

UPDATE exp_matrix_data
SET col_id_X = CONCAT('{filedir_Y}', col_id_X)
WHERE col_id_X != ''
AND col_id_X NOT LIKE '{filedir_%'

Again, X == your Matrix column ID (you can get that from exp_matrix_cols), and Y == your upload preference ID.

(Credit goes to Rob Sanchez, of course.)

like image 76
Brandon Kelly Avatar answered Nov 16 '22 23:11

Brandon Kelly


I wrote this for a site as well - no matrix support in here but it works quickly and correctly for regular fields.

For the array, the left column is each field ID that you changed to text pre-upgrade, and needs to be changed to file post upgrade, and the right side is the X of filedir_X for the file upload dir you want to attach to the field

// Insert file upload directories

$array = array(
    '16' => '1',
    '22' => '1',
    '121' => '3',
    '58' => '1',
    '67' => '1',
    '68' => '1',
    '71' => '1',
    '76' => '1',
    '78' => '1',
    '94' => '1',
    '99' => '1',
    '108' => '3',
    '109' => '3',
    '110' => '3',
    '139' => '1'
    );

foreach($array as $field_id => $dir_id) {

    $q_entries = $this->EE->db->query("SELECT entry_id, field_id_{$field_id} as 'field' from exp_channel_data where field_id_{$field_id} != '' order by entry_id asc");

        if ($q_entries->num_rows() > 0) {

            echo '<h3>field_id_'.$field_id.'</h3>';

            foreach($q_entries->result_array() as $entry) {

                echo $entry['entry_id'];

                $filename = trim('{filedir_'.$dir_id.'}'.$entry['field']);

                echo ' - '.$filename.'<br/>';

                $data = array(
                    'field_id_'.$field_id => $filename,
                    );
                $sql = $this->EE->db->update_string('exp_channel_data', $data, "entry_id = '{$entry['entry_id']}'");
                $this->EE->db->query($sql);

            }
        }

}

echo 'done';
like image 21
Chad Crowell Avatar answered Nov 17 '22 01:11

Chad Crowell


I have an entire blog post about this which is based off of my experience and the thread that Brandon referenced in his answer. Blog post here.

like image 5
CreateSean Avatar answered Nov 17 '22 00:11

CreateSean