From 720d3dcedc96c7aaf6c4444c8b45acd46b8718b0 Mon Sep 17 00:00:00 2001 From: Mario Date: Wed, 11 Mar 2020 10:34:25 +0000 Subject: z6trans preparation for db update 1236 --- Zotlabs/Module/Z6trans.php | 118 +++++++++------------------------------------ 1 file changed, 24 insertions(+), 94 deletions(-) (limited to 'Zotlabs') diff --git a/Zotlabs/Module/Z6trans.php b/Zotlabs/Module/Z6trans.php index ac8c67c79..98832ad98 100644 --- a/Zotlabs/Module/Z6trans.php +++ b/Zotlabs/Module/Z6trans.php @@ -12,116 +12,50 @@ use Zotlabs\Web\Controller; class Z6trans extends Controller { - function post() { - if(!is_site_admin()) - return; - - $zot_xchan = trim($_POST['zot_xchan']); - - $r = q("SELECT xchan_guid FROM xchan WHERE xchan_hash = '%s' AND xchan_network = 'zot'", - dbesc($zot_xchan) - ); - - if(!$r) { - notice(t('Zot xchan not found. Aborting.') . EOL); - return; - } - - $guid = $r[0]['xchan_guid']; - $r = q("SELECT xchan_hash, xchan_guid_sig FROM xchan WHERE xchan_guid = '%s' AND xchan_network = 'zot6'", - dbesc($guid) - ); - - if(!$r) { - notice(t('No zot6 xchan found. Aborting.') . EOL); - return; - } - - $zot6_xchan = $r[0]['xchan_hash']; - $zot6_xchan_guid_sig = $r[0]['xchan_guid_sig']; - - - $r = q("SELECT * FROM channel WHERE channel_hash = '%s'", - dbesc($zot_xchan) - ); - - // We got everything we need - start transforming. - - if($r) { - logger("Transforming channel $zot_xchan"); - q("UPDATE channel SET channel_hash = '%s', channel_portable_id = '%s', channel_guid_sig = '%s' WHERE channel_hash = '%s'", - dbesc($zot6_xchan), - dbesc($zot_xchan), - dbesc($zot6_xchan_guid_sig), - dbesc($zot_xchan) - ); - } - - $core = self::get_core_cols(); - - foreach($core as $table => $cols) { - foreach($cols as $col) { - logger("Transforming $table - $col"); - q("UPDATE %s SET %s = replace(%s, '%s', '%s')", - dbesc($table), - dbesc($col), - dbesc($col), - dbesc($zot_xchan), - dbesc($zot6_xchan) - ); - } - logger("$table done."); - } - logger("Transformation completed."); - - - - } - function get() { if(!is_site_admin()) return 'Not Allowed'; - $path = 'store/z6upgrade.sql'; + $path = 'store/z6trans.sql'; - $r = q("SELECT channel.channel_name, channel.channel_hash, xchan.xchan_network FROM channel LEFT JOIN xchan ON channel_hash = xchan_hash WHERE xchan.xchan_network = 'zot' AND channel.channel_removed = 0"); + $r = q("SELECT channel.channel_name, channel.channel_portable_id, xchan.xchan_network FROM channel + LEFT JOIN xchan ON channel_portable_id = xchan_hash + WHERE xchan.xchan_network = 'zot' + AND channel.channel_removed = 0" + ); + + $q = ''; foreach($r as $rr) { - $zot_xchan = $rr['channel_hash']; + $zot_xchan = $rr['channel_portable_id']; $r = q("SELECT xchan_guid FROM xchan WHERE xchan_hash = '%s' AND xchan_network = 'zot'", dbesc($zot_xchan) ); if(!$r) { - notice(t('Zot xchan not found. Aborting.') . EOL); - return; + $q .= '-- ' . $zot_xchan . 'failed: zot xchan not found' . "\r\n"; + continue; } $guid = $r[0]['xchan_guid']; + $r = q("SELECT xchan_hash, xchan_guid_sig FROM xchan WHERE xchan_guid = '%s' AND xchan_network = 'zot6'", dbesc($guid) ); if(!$r) { - notice(t('No zot6 xchan found. Aborting.') . EOL); - return; + $q .= '-- ' . $zot_xchan . 'failed: zot6 xchan not found' . "\r\n"; + continue; } $zot6_xchan = $r[0]['xchan_hash']; - $zot6_xchan_guid_sig = $r[0]['xchan_guid_sig']; - - //this should probably happen in a db_update during upgrading - $q .= sprintf("UPDATE channel SET channel_hash = '%s', channel_portable_id = '%s', channel_guid_sig = '%s' WHERE channel_hash = '%s';\r\n", - dbesc($zot6_xchan), - dbesc($zot_xchan), - dbesc($zot6_xchan_guid_sig), - dbesc($zot_xchan) - ); $core = self::get_core_cols(); + $q .= '-- Transforming ' . $rr['channel_name'] . "\r\n"; + foreach($core as $table => $cols) { foreach($cols as $col) { @@ -138,24 +72,20 @@ class Z6trans extends Controller { } - file_put_contents($path, $q); - } + if($q) + file_put_contents($path, $q); - $o = '

' . t('Transform a single channel') . '

'; - $o .= '
'; - $o .= t('Enter zot xchan to transform: ') . '
'; - $o .= '
'; - $o .= '
'; - $o .= '


'; - + $o = '

' . t('Update to Hubzilla 5.0 setp 2') . '


'; - $o .= '

' . t('To transform all channels') . '

'; + $o .= '

' . t('To complete the update please run') . '

'; if(ACTIVE_DBTYPE == DBTYPE_MYSQL) - $o .= 'Run source ' . $_SERVER["DOCUMENT_ROOT"] . '/' . $path . ' from the mysql console to complete the upgrade.'; + $o .= 'source ' . $_SERVER["DOCUMENT_ROOT"] . '/' . $path . '

from the mysql console.

'; else - $o .= 'Run \i ' . $_SERVER["DOCUMENT_ROOT"] . '/' . $path . ' from the postgresql console to complete the upgrade.'; + $o .= '\i ' . $_SERVER["DOCUMENT_ROOT"] . '/' . $path . '

from the postgresql console.

'; + + $o .= '

' . t('INFO: this command can take a very long time depending on your DB size.') . '

'; return $o; -- cgit v1.2.3