ExpressionEngine 1 to ExpressionEngine 2 Upgrade with nGen File Field
Asked Answered
K

5

10

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?

Kashgar answered 24/10, 2012 at 0:49 Comment(0)
P
21

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.)

Placket answered 24/10, 2012 at 0:58 Comment(1)
Perfect. Thank you Brandon! I do use Matrix on the site.Kashgar
D
6

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';
Domineering answered 30/10, 2012 at 20:57 Comment(0)
D
5

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.

Demetrius answered 24/10, 2012 at 1:10 Comment(0)
F
0

I've posted something to GitHub that should help anyone facing this process. It's EE1 template code (it needs PHP enabled on either output or input) that shows two things:

Firstly, it displays a tabular overview of all custom fields in the system. This is for reference, to help when you're trying to find all instances of a certain fieldtype. It covers normal EE fields, Fieldframe fieldtypes, and even Matrix columns.

Secondly, each time an nGen File field is encountered, the template generates the MySQL code you'll need to use (after you upgrade to EE2) to alter the data in said fields to the format required by EE2's native File field. These queries are only displayed, not run. The idea is that you save the queries somewhere, run the EE1->EE2 upgrade, and then run the saved queries when ready.

Needless to say, backup, Backup, BACKUP. The template code does not modify your site database in any way, and has been tested and displays what its supposed to just fine. However, while the MySQL queries it generates (for you to copy and manually run later) match what Brandon recommended in his answer, I have yet to actually test those queries in action.

Footloose answered 29/6, 2014 at 17:43 Comment(5)
Hah! What goes around comes around... I learned EE back in 2007 from your "Building a Church Website" tutorials, so I'm glad I was able to contribute something back! ;)Footloose
Hey - just getting around to being able to run this. The script isn't seeing my nGen File Fields and isn't generating the SQL that I see in your examples. I'm in EE1.7.1 yet & haven't converted any field types. nGen / Matrix seem to be running OK as I can add a new Matrix column with a new nGen File field.Uptrend
Does the template have PHP enabled?Footloose
Ok, instead of cluttering things up here, open up an issue in the repo on GitHub. Include as much information as think will help, esp. things like PHP versions and whatnot. I just tried out the repo on a site I still have on 1.7.1, and aside from the BR constant not being defined, it works fine.Footloose
OK - left an issue on GitHub.Uptrend
M
0

The best way to do this is to proceed carefully and make backups of your database at each step of the way. I have previously written a blog post on this but will elaborate further.

Step 1: Before running your upgrade change all ngen field types to text, don't worry the data won't be lost.

Step 2: Next upgrade ExpressionEngine as per the official docs and then go back into each field and change them to the first party file type.

The next step involves a little bit of database manipulation, but it's just copying and paste so don't worry.

Step 3: Do make a back up of your database before you proceed just in case.

Step 4: This next step depends whether your original nGen file field was in a standard Channel Field or a Matrix Field.

Now go into your database and 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.

(To find your upload preference ID in your control panel, go to Content > Files > File Upload Preferences. Choose the ID column on the left that matches the file upload location.)

4a: If updating standard Channel Fields, use this 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_%'

4b: For matrix, fields run this 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_%'

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

Credit to Brandon Kelly and Rob Sanchez.

Additionally, the same procedure can be used for other add-ons that don't exist in EE2. Convert to text before the upgrade and then convert to a new equivalent field type post upgrade if needed. For more help: Click here

Mitra answered 30/11, 2017 at 4:19 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.