Last active
August 29, 2015 14:11
-
-
Save kmeinke/53d28d3bdbf1832c1954 to your computer and use it in GitHub Desktop.
update reference_link to association_field #untestet - psuedo code#
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<? | |
die("untestet code - do not use without checking"); | |
//connect | |
$mysqli = new mysqli("localhost", "user", "password", "database"); | |
//install assoc field first | |
$result = $mysqli->query("SHOW TABLES LIKE 'sym_fields_association';"); | |
if ($result->num_rows == 0) | |
die("install Assoc Field first"); | |
$result->free(); | |
//update all autocomplete entries tables | |
$result = $mysqli->query("Select * From sym_referencelink Where field_type = 'autocomplete'"); | |
$rlData = $result->fetch_all(MYSQLI_ASSOC); | |
$result->free(); | |
foreach ($rlData as $rlField) { | |
$mysqli->query("ALTER TABLE sym_entries_data_".$rlField['field_id']." ADD COLUMN relation_id int(11) NULL AFTER entry_id;"); | |
$mysqli->query("Update sym_entries_data_".$rlField['field_id']." AS parent Inner Join sym_entries_data_".$rlField['related_field_id']." AS child ON child.handle = parent.handle Set parent.relation_id = child.entry_id"); | |
$mysqli->query("ALTER TABLE sym_entries_data_".$rlField['field_id']." DROP COLUMN handle, DROP COLUMN value;"); | |
} | |
//update sym_fields_association | |
$mysqli->query("Insert Into sym_fields_association (field_id, allow_multiple_selection, hide_when_prepopulated, related_field_id, limit)" | |
_ " Select sl.field_id, sl.allow_multiple_selection, sl.hide_when_prepopulated, sl.related_field_id From sym_referencelink as sl"); | |
//update sym_fields | |
$mysqli->query("Update sym_fields as f Set f.type = 'association' Where f.type = 'referencelink'"); | |
die("db upgrade complete. disable referencelink extension and test installation"); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment