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?
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?
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.)
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';
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.
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.
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
© 2022 - 2024 — McMap. All rights reserved.