2010-04-20 21:35:20 +00:00
< ? php
/*
+ ----------------------------------------------------------------------------+
| e107 website system
|
2010-10-21 17:42:03 +00:00
| Copyright ( C ) 2008 - 2010 e107 Inc ( e107 . org )
2010-04-20 21:35:20 +00:00
| http :// e107 . org
|
|
| Released under the terms and conditions of the
| GNU General Public License ( http :// gnu . org ) .
|
2010-10-21 17:42:03 +00:00
| $URL $
| $Revision $
| $Id $
| $Author $
2010-04-20 21:35:20 +00:00
+----------------------------------------------------------------------------+
*/
/**
* @ package e107
* @ subpackage admin
2012-12-08 15:52:40 +01:00
* @ version $Id $ ;
2010-04-20 21:35:20 +00:00
*
* Update routines from older e107 versions to current .
*
* Also links to plugin update routines .
*
* 2 - stage process - routines identify whether update is required , and then execute as instructed .
*/
// [debug=8] shows the operations on major table update
require_once ( '../class2.php' );
require_once ( e_HANDLER . 'db_table_admin_class.php' );
include_lan ( e_LANGUAGEDIR . e_LANGUAGE . '/admin/lan_e107_update.php' );
// Modified update routine - combines checking and update code into one block per function
// - reduces code size typically 30%.
// - keeping check and update code together should improve clarity/reduce mis-types etc
2010-10-21 17:42:03 +00:00
// @todo: how do we handle update of multi-language tables?
2010-04-20 21:35:20 +00:00
// If following line uncommented, enables a test routine
// define('TEST_UPDATE',TRUE);
2013-03-27 19:34:45 -07:00
$update_debug = TRUE ; // TRUE gives extra messages in places
2010-04-20 21:35:20 +00:00
//$update_debug = TRUE; // TRUE gives extra messages in places
if ( defined ( 'TEST_UPDATE' )) $update_debug = TRUE ;
if ( ! defined ( 'LAN_UPDATE_8' )) { define ( 'LAN_UPDATE_8' , '' ); }
if ( ! defined ( 'LAN_UPDATE_9' )) { define ( 'LAN_UPDATE_9' , '' ); }
// Determine which installed plugins have an update file - save the path and the installed version in an array
$dbupdateplugs = array (); // Array of paths to installed plugins which have a checking routine
$dbupdatep = array (); // Array of plugin upgrade actions (similar to $dbupdate)
$dbupdate = array (); // Array of core upgrade actions
global $e107cache ;
if ( is_readable ( e_ADMIN . 'ver.php' ))
{
include ( e_ADMIN . 'ver.php' );
}
2012-12-03 15:04:11 -08:00
$mes = e107 :: getMessage ();
2010-04-20 21:35:20 +00:00
// If $dont_check_update is both defined and TRUE on entry, a check for update is done only once per 24 hours.
$dont_check_update = varset ( $dont_check_update , FALSE );
if ( $dont_check_update === TRUE )
{
$dont_check_update = FALSE ;
if ( $tempData = $e107cache -> retrieve_sys ( 'nq_admin_updatecheck' , 3600 , TRUE ))
{ // See when we last checked for an admin update
list ( $last_time , $dont_check_update , $last_ver ) = explode ( ',' , $tempData );
if ( $last_ver != $e107info [ 'e107_version' ])
{
$dont_check_update = FALSE ; // Do proper check on version change
}
}
}
2012-04-20 07:19:58 +00:00
2010-04-20 21:35:20 +00:00
if ( ! $dont_check_update )
{
2012-12-08 00:36:34 -08:00
/*
2012-04-20 07:19:58 +00:00
if ( $sql -> db_Select ( 'plugin' , 'plugin_id, plugin_version, plugin_path' , 'plugin_installflag=1' ))
2010-04-20 21:35:20 +00:00
{
while ( $row = $sql -> db_Fetch ())
{ // Mark plugins for update which have a specific update file, or a plugin.php file to check
2012-04-20 07:19:58 +00:00
if ( is_readable ( e_PLUGIN . $row [ 'plugin_path' ] . '/' . $row [ 'plugin_path' ] . '_update_check.php' ) || is_readable ( e_PLUGIN . $row [ 'plugin_path' ] . '/plugin.php' ) || is_readable ( e_PLUGIN . $row [ 'plugin_path' ] . '/' . $row [ 'plugin_path' ] . '_setup.php' ))
2010-04-20 21:35:20 +00:00
{
$dbupdateplugs [ $row [ 'plugin_path' ]] = $row [ 'plugin_version' ];
2012-04-20 07:19:58 +00:00
//TODO - Add support for {plugins}_setup.php upgrade check and routine.
2010-04-20 21:35:20 +00:00
}
}
}
2012-12-08 00:36:34 -08:00
*/
2012-12-16 14:28:30 -08:00
if ( $dbupdateplugs = e107 :: getConfig ( 'core' ) -> get ( 'plug_installed' ))
2010-04-20 21:35:20 +00:00
{
2012-12-16 14:28:30 -08:00
// Read in each update file - this will add an entry to the $dbupdatep array if a potential update exists
foreach ( $dbupdateplugs as $path => $ver )
2012-04-20 07:19:58 +00:00
{
2012-12-16 14:28:30 -08:00
if ( ! is_file ( e_PLUGIN . $path . " /plugin.xml " ))
{
$fname = e_PLUGIN . $path . '/' . $path . '_update_check.php' ; // DEPRECATED - left for BC only.
if ( is_readable ( $fname )) include_once ( $fname );
}
$fname = e_PLUGIN . $path . '/' . $path . '_setup.php' ;
if ( is_readable ( $fname ))
{
$dbupdatep [ $path ] = $path ; // ' 0.7.x forums '.LAN_UPDATE_9.' 0.8 forums';
include_once ( $fname );
}
}
2010-04-20 21:35:20 +00:00
}
2013-03-27 19:34:45 -07:00
2010-04-20 21:35:20 +00:00
// List of potential updates
if ( defined ( 'TEST_UPDATE' ))
{
$dbupdate [ 'test_code' ] = 'Test update routine' ;
}
2013-03-27 19:34:45 -07:00
// set 'master' to true to prevent other upgrades from running before it is complete.
2013-04-18 22:06:56 +01:00
$dbupdate [ '706_to_800' ] = array ( 'master' => true , 'title' => LAN_UPDATE_8 . ' 1.x ' . LAN_UPDATE_9 . ' 2.0' , 'message' => LAN_UPDATE_29 );
2013-03-27 19:34:45 -07:00
$dbupdate [ 'core_prefs' ] = array ( 'master' => true , 'title' => LAN_UPDATE_13 ); // Prefs check
2012-12-07 15:16:42 -08:00
// $dbupdate['70x_to_706'] = LAN_UPDATE_8.' .70x '.LAN_UPDATE_9.' .706';
2010-04-20 21:35:20 +00:00
} // End if (!$dont_check_update)
2013-05-04 19:59:54 -07:00
// New in v2.x ------------------------------------------------
class e107Update
{
var $core = array ();
var $updates = 0 ;
var $disabled = 0 ;
function __construct ( $core = null )
{
$mes = e107 :: getMessage ();
$this -> core = $core ;
if ( varset ( $_POST [ 'update_core' ]) && is_array ( $_POST [ 'update_core' ]))
{
$func = key ( $_POST [ 'update_core' ]);
$message = $this -> updateCore ( $func );
}
if ( varset ( $_POST [ 'update' ]) && is_array ( $_POST [ 'update' ])) // Do plugin updates
{
$func = key ( $_POST [ 'update' ]);
$this -> updatePlugin ( $func );
}
if ( vartrue ( $message ))
{
$mes -> addSuccess ( $message );
}
$this -> renderForm ();
}
function updateCore ( $func = '' )
{
$mes = e107 :: getMessage ();
// foreach($this->core as $func => $data)
// {
if ( function_exists ( 'update_' . $func )) // Legacy Method.
{
$installed = call_user_func ( " update_ " . $func );
//?! (LAN_UPDATE == $_POST[$func])
if ( varsettrue ( $_POST [ 'update_core' ][ $func ]) && ! $installed )
{
if ( function_exists ( " update_ " . $func ))
{
$message = LAN_UPDATE_7 . " " . $data [ 'title' ];
$error = call_user_func ( " update_ " . $func , " do " );
if ( $error != '' )
{
$mes -> add ( $message , E_MESSAGE_ERROR );
$mes -> add ( $error , E_MESSAGE_ERROR );
}
else
{
$mes -> add ( $message , E_MESSAGE_SUCCESS );
}
}
}
}
else
{
$mes -> addDebug ( " could run 'update_ " . $func );
}
//}
}
function updatePlugin ( $path )
{
e107 :: getPlugin () -> install_plugin_xml ( $path , 'upgrade' );
}
function plugins ()
{
if ( ! $list = e107 :: getPlugin () -> updateRequired ())
{
return ;
}
$frm = e107 :: getForm ();
$text = " " ;
foreach ( $list as $path => $val )
{
$text .= " <tr>
< td > " . $val['@attributes'] ['name']. " </ td >
< td > " . $frm->admin_button ('update['. $path .']', LAN_UPDATE, 'warning', '', 'disabled='. $this->disabled ). " </ td >
</ tr > " ;
}
return $text ;
}
function core ()
{
$frm = e107 :: getForm ();
$mes = e107 :: getMessage ();
$text = " " ;
foreach ( $this -> core as $func => $data )
{
if ( function_exists ( " update_ " . $func ))
{
$text .= " <tr><td> " . $data [ 'title' ] . " </td> " ;
if ( call_user_func ( " update_ " . $func ))
{
$text .= " <td> " . ADMIN_TRUE_ICON . " </td> " ;
}
else
{
if ( vartrue ( $data [ 'message' ]))
{
$mes -> addInfo ( $data [ 'message' ]);
}
$this -> updates ++ ;
$text .= " <td> " . $frm -> admin_button ( 'update_core[' . $func . ']' , LAN_UPDATE , 'warning' , '' , " id=e- { $func } &disabled= " . $this -> disabled ) . " </td> " ;
if ( $data [ 'master' ] == true )
{
$this -> disabled = 1 ;
}
}
$text .= " </tr> \n " ;
}
}
return $text ;
}
function renderForm ()
{
$ns = e107 :: getRender ();
$mes = e107 :: getMessage ();
$caption = LAN_UPDATE ;
$text = "
< form method = 'post' action = '".e_SELF."' >
< fieldset id = 'core-e107-update' >
< legend > { $caption } </ legend >
< table class = 'table adminlist' >
< colgroup >
< col style = 'width: 60%' />
< col style = 'width: 40%' />
</ colgroup >
< thead >
< tr >
< th > " .LAN_UPDATE_55. " </ th >
< th class = 'last' > " .LAN_UPDATE_2. " </ th >
</ tr >
</ thead >
< tbody >
" ;
$text .= $this -> core ();
$text .= $this -> plugins ();
$text .= "
</ tbody >
</ table >
</ fieldset >
</ form >
" ;
$ns -> tablerender ( " Updates " , $mes -> render () . $text );
}
}
2010-04-20 21:35:20 +00:00
/**
* Master routine to call to check for updates
*/
function update_check ()
{
2012-07-23 09:35:32 +00:00
2012-12-08 00:36:34 -08:00
$ns = e107 :: getRender ();
$e107cache = e107 :: getCache ();
$sql = e107 :: getDb ();
$mes = e107 :: getMessage ();
2012-07-23 09:35:32 +00:00
2012-12-08 00:36:34 -08:00
global $dont_check_update , $e107info ;
global $dbupdate , $dbupdatep , $e107cache ;
2010-04-20 21:35:20 +00:00
$update_needed = FALSE ;
if ( $dont_check_update === FALSE )
{
2012-12-08 00:36:34 -08:00
foreach ( $dbupdate as $func => $rmks ) // See which core functions need update
2010-04-20 21:35:20 +00:00
{
if ( function_exists ( 'update_' . $func ))
{
if ( ! call_user_func ( 'update_' . $func , FALSE ))
{
$update_needed = TRUE ;
2012-12-08 00:36:34 -08:00
break ;
2010-04-20 21:35:20 +00:00
}
}
}
2012-12-08 00:36:34 -08:00
// Now check plugins - XXX DEPRECATED
2010-04-20 21:35:20 +00:00
foreach ( $dbupdatep as $func => $rmks )
{
if ( function_exists ( 'update_' . $func ))
{
if ( ! call_user_func ( 'update_' . $func , FALSE ))
{
$update_needed = TRUE ;
2012-12-08 00:36:34 -08:00
break ;
2010-04-20 21:35:20 +00:00
}
}
}
2012-12-08 00:36:34 -08:00
// New in v2.x
if ( e107 :: getPlugin () -> updateRequired ( 'boolean' ))
{
$update_needed = TRUE ;
}
2010-04-20 21:35:20 +00:00
2012-12-08 00:36:34 -08:00
// $e107cache->set_sys('nq_admin_updatecheck', time().','.($update_needed ? '2,' : '1,').$e107info['e107_version'], TRUE);
2010-04-20 21:35:20 +00:00
}
else
{
$update_needed = ( $dont_check_update == '2' );
}
if ( $update_needed === TRUE )
{
2012-12-08 00:36:34 -08:00
$frm = e107 :: getForm ();
2010-04-20 21:35:20 +00:00
$txt = "
< form method = 'post' action = '".e_ADMIN_ABS."e107_update.php' >
< div >
" .ADLAN_120. "
2012-12-08 00:36:34 -08:00
" . $frm->admin_button ('e107_system_update', LAN_UPDATE, 'other'). "
2010-04-20 21:35:20 +00:00
</ div >
</ form >
" ;
2012-12-08 00:36:34 -08:00
$mes -> addInfo ( $txt );
2010-04-20 21:35:20 +00:00
}
}
2012-07-23 09:35:32 +00:00
2012-12-08 00:36:34 -08:00
//XXX to be reworked eventually - for checking remote 'new versions' of plugins and installed theme.
// require_once(e_HANDLER.'e_upgrade_class.php');
2010-04-20 21:35:20 +00:00
// $upg = new e_upgrade;
2012-12-08 00:36:34 -08:00
2010-04-20 21:35:20 +00:00
// $upg->checkSiteTheme();
// $upg->checkAllPlugins();
2012-12-08 00:36:34 -08:00
2010-04-20 21:35:20 +00:00
//--------------------------------------------
// Check current prefs against latest list
//--------------------------------------------
function update_core_prefs ( $type = '' )
{
2013-03-28 00:41:29 -07:00
global $e107info ; // $pref, $pref must be kept as global
$pref = e107 :: getConfig ( 'core' , true , true ) -> getPref ();
2010-04-20 21:35:20 +00:00
$admin_log = e107 :: getAdminLog ();
$do_save = FALSE ;
$should = get_default_prefs ();
$just_check = $type == 'do' ? FALSE : TRUE ; // TRUE if we're just seeing if an update is needed
foreach ( $should as $k => $v )
{
if ( $k && ! array_key_exists ( $k , $pref ))
{
if ( $just_check ) return update_needed ( 'Missing pref: ' . $k );
$pref [ $k ] = $v ;
$admin_log -> logMessage ( $k . ' => ' . $v , E_MESSAGE_NODISPLAY , E_MESSAGE_INFO );
$do_save = TRUE ;
}
}
if ( $do_save )
{
2013-03-28 00:41:29 -07:00
//save_prefs();
e107 :: getConfig ( 'core' ) -> setPref ( $pref ) -> save ();
2010-04-20 21:35:20 +00:00
$admin_log -> logMessage ( LAN_UPDATE_14 . $e107info [ 'e107_version' ], E_MESSAGE_NODISPLAY , E_MESSAGE_INFO );
$admin_log -> flushMessages ( 'UPDATE_03' , E_LOG_INFORMATIVE );
//$admin_log->log_event('UPDATE_03',LAN_UPDATE_14.$e107info['e107_version'].'[!br!]'.implode(', ',$accum),E_LOG_INFORMATIVE,''); // Log result of actual update
}
return $just_check ;
}
if ( defined ( 'TEST_UPDATE' ))
{
//--------------------------------------------
// Test routine - to activate, define TEST_UPDATE
//--------------------------------------------
function update_test_code ( $type = '' )
{
global $sql , $ns , $pref ;
$just_check = $type == 'do' ? FALSE : TRUE ; // TRUE if we're just seeing whether an update is needed
//--------------**************---------------
// Add your test code in here
//--------------**************---------------
//--------------**************---------------
// End of test code
//--------------**************---------------
return $just_check ;
}
} // End of test routine
//--------------------------------------------
// Upgrade later versions of 0.7.x to 0.8
//--------------------------------------------
function update_706_to_800 ( $type = '' )
{
2012-12-08 00:36:34 -08:00
global $pref , $e107info ;
2010-10-21 17:42:03 +00:00
global $sysprefs , $eArrayStorage ;
2010-04-20 21:35:20 +00:00
//$mes = new messageLog; // Combined logging and message displaying handler
//$mes = e107::getMessage();
2013-05-12 20:56:35 -07:00
$log = e107 :: getAdminLog (); // Used for combined logging and message displaying
$sql = e107 :: getDb ();
$sql2 = e107 :: getDb ( 'sql2' );
$tp = e107 :: getParser ();
$ns = e107 :: getRender ();
2012-12-03 15:04:11 -08:00
2012-04-26 01:33:33 +00:00
e107 :: getCache () -> clearAll ( 'db' );
2013-03-28 00:41:29 -07:00
e107 :: getCache () -> clearAll ( 'system' );
2010-04-20 21:35:20 +00:00
// List of unwanted $pref values which can go
$obs_prefs = array ( 'frontpage_type' , 'rss_feeds' , 'log_lvcount' , 'zone' , 'upload_allowedfiletype' , 'real' , 'forum_user_customtitle' ,
'utf-compatmode' , 'frontpage_method' , 'standards_mode' , 'image_owner' , 'im_quality' , 'signup_option_timezone' ,
'modules' , 'plug_sc' , 'plug_bb' , 'plug_status' , 'plug_latest' , 'subnews_hide_news' , 'upload_storagetype'
2012-12-08 00:36:34 -08:00
);
2010-04-20 21:35:20 +00:00
// List of DB tables not required (includes a few from 0.6xx)
2012-08-12 07:13:02 +00:00
$obs_tables = array ( 'flood' , 'headlines' , 'stat_info' , 'stat_counter' , 'stat_last' , 'session' , 'preset' , 'tinymce' );
2010-04-20 21:35:20 +00:00
// List of DB tables newly required (defined in core_sql.php) (The existing dblog table gets renamed)
2011-06-15 05:41:06 +00:00
// No Longer required. - automatically checked against core_sql.php.
// $new_tables = array('audit_log', 'dblog', 'news_rewrite', 'core_media', 'core_media_cat','cron', 'mail_recipients', 'mail_content');
2012-12-08 15:52:40 +01:00
// List of core prefs that need to be converted from serialized to e107ArrayStorage.
2013-04-25 20:05:32 -07:00
$serialized_prefs = array ( " 'emote' " , " 'menu_pref' " , " 'search_prefs' " , " 'emote_default' " , " 'pm_prefs' " );
2010-04-20 21:35:20 +00:00
2013-05-17 18:17:04 -07:00
$create_dir = array ( e_MEDIA , e_SYSTEM , e_CACHE , e_CACHE_CONTENT , e_CACHE_IMAGE , e_CACHE_DB , e_LOG , e_BACKUP , e_CACHE_URL , e_TEMP , e_IMPORT );
2012-12-07 15:16:42 -08:00
foreach ( $create_dir as $dr )
{
if ( ! is_dir ( $dr ))
{
mkdir ( $dr , 0755 );
}
}
2010-04-20 21:35:20 +00:00
// List of changed DB tables (defined in core_sql.php)
2011-06-15 05:41:06 +00:00
// No Longer required. - automatically checked against core_sql.php.
2010-04-20 21:35:20 +00:00
// (primarily those which have changed significantly; for the odd field write some explicit code - it'll run faster)
2012-12-08 15:52:40 +01:00
// $changed_tables = array('user', 'dblog', 'admin_log', 'userclass_classes', 'banlist', 'menus',
2011-06-15 05:41:06 +00:00
// 'plugin', 'news', 'news_category', 'online', 'page', 'links', 'comments');
2010-04-20 21:35:20 +00:00
// List of changed DB tables from core plugins (defined in pluginname_sql.php file)
// key = plugin directory name. Data = comma-separated list of tables to check
// (primarily those which have changed significantly; for the odd field write some explicit code - it'll run faster)
2011-06-15 05:41:06 +00:00
// No Longer required. - automatically checked by db-verify
2012-12-08 15:52:40 +01:00
/* $pluginChangedTables = array ( 'linkwords' => 'linkwords' ,
2010-04-20 21:35:20 +00:00
'featurebox' => 'featurebox' ,
'links_page' => 'links_page' ,
'poll' => 'polls' ,
'content' => 'pcontent'
);
2011-06-15 05:41:06 +00:00
*/
2012-12-08 15:52:40 +01:00
/*
2012-06-07 00:33:10 +00:00
$setCorePrefs = array ( //modified prefs during upgrade.
2012-12-07 15:16:42 -08:00
'adminstyle' => 'infopanel' ,
'admintheme' => 'bootstrap' ,
'admincss' => 'admin_style.css' ,
'resize_dimensions' => array (
'news-image' => array ( 'w' => 250 , 'h' => 250 ),
'news-bbcode' => array ( 'w' => 250 , 'h' => 250 ),
'page-bbcode' => array ( 'w' => 250 , 'h' => 250 )
)
2010-04-20 21:35:20 +00:00
);
2012-12-07 15:16:42 -08:00
*/
2010-04-20 21:35:20 +00:00
2012-06-07 00:33:10 +00:00
$do_save = TRUE ;
2012-12-08 15:52:40 +01:00
// List of changed menu locations.
2010-04-20 21:35:20 +00:00
$changeMenuPaths = array (
array ( 'oldpath' => 'siteinfo_menu' , 'newpath' => 'siteinfo' , 'menu' => 'sitebutton_menu' ),
array ( 'oldpath' => 'siteinfo_menu' , 'newpath' => 'siteinfo' , 'menu' => 'compliance_menu' ),
array ( 'oldpath' => 'siteinfo_menu' , 'newpath' => 'siteinfo' , 'menu' => 'powered_by_menu' ),
array ( 'oldpath' => 'siteinfo_menu' , 'newpath' => 'siteinfo' , 'menu' => 'sitebutton_menu' ),
array ( 'oldpath' => 'siteinfo_menu' , 'newpath' => 'siteinfo' , 'menu' => 'counter_menu' ),
2012-12-08 15:52:40 +01:00
array ( 'oldpath' => 'siteinfo_menu' , 'newpath' => 'siteinfo' , 'menu' => 'latestnews_menu' ),
2010-04-20 21:35:20 +00:00
array ( 'oldpath' => 'compliance_menu' , 'newpath' => 'siteinfo' , 'menu' => 'compliance_menu' ),
array ( 'oldpath' => 'powered_by_menu' , 'newpath' => 'siteinfo' , 'menu' => 'powered_by_menu' ),
array ( 'oldpath' => 'sitebutton_menu' , 'newpath' => 'siteinfo' , 'menu' => 'sitebutton_menu' ),
array ( 'oldpath' => 'counter_menu' , 'newpath' => 'siteinfo' , 'menu' => 'counter_menu' ),
2014-01-22 00:04:50 -08:00
array ( 'oldpath' => 'usertheme_menu' , 'newpath' => 'user' , 'menu' => 'usertheme_menu' ),
array ( 'oldpath' => 'userlanguage_menu' , 'newpath' => 'user' , 'menu' => 'userlanguage_menu' ),
2012-11-01 02:21:58 +00:00
array ( 'oldpath' => 'lastseen_menu' , 'newpath' => 'online' , 'menu' => 'lastseen_menu' ),
array ( 'oldpath' => 'other_news_menu' , 'newpath' => 'news' , 'menu' => 'other_news_menu' ),
2014-01-22 00:04:50 -08:00
array ( 'oldpath' => 'other_news_menu' , 'newpath' => 'news' , 'menu' => 'other_news2_menu' ),
array ( 'oldpath' => 'user_menu' , 'newpath' => 'user' , 'menu' => 'usertheme_menu' ),
array ( 'oldpath' => 'user_menu' , 'newpath' => 'user' , 'menu' => 'userlanguage_menu' ),
2014-01-22 07:33:31 -08:00
array ( 'oldpath' => 'poll_menu' , 'newpath' => 'poll' , 'menu' => 'poll_menu' ),
array ( 'oldpath' => 'banner_menu' , 'newpath' => 'banner' , 'menu' => 'banner_menu' ),
array ( 'oldpath' => 'online_menu' , 'newpath' => 'online' , 'menu' => 'online_menu' ),
2012-12-08 15:52:40 +01:00
);
2010-04-20 21:35:20 +00:00
// List of DB tables (key) and field (value) which need changing to accommodate IPV6 addresses
$ip_upgrade = array ( 'download_requests' => 'download_request_ip' ,
2011-06-15 05:41:06 +00:00
'submitnews' => 'submitnews_ip' ,
'tmp' => 'tmp_ip' ,
'chatbox' => 'cb_ip'
2010-04-20 21:35:20 +00:00
);
$db_parser = new db_table_admin ; // Class to read table defs and process them
$do_save = FALSE ; // Set TRUE to update prefs when update complete
$updateMessages = array (); // Used to log actions for the admin log - TODO: will go once all converted to new class
$just_check = $type == 'do' ? FALSE : TRUE ; // TRUE if we're just seeing whether an update is needed
2014-01-20 06:20:58 -08:00
// if (!$just_check)
// {
// foreach(vartrue($setCorePrefs) as $k=>$v)
// {
// $pref[$k] = $v;
// }
// }
2010-04-20 21:35:20 +00:00
if ( ! $just_check )
{
2012-12-03 15:04:11 -08:00
$log -> logMessage ( LAN_UPDATE_14 . $e107info [ 'e107_version' ], E_MESSAGE_NODISPLAY );
2010-04-20 21:35:20 +00:00
}
2013-03-28 00:41:29 -07:00
2010-04-20 21:35:20 +00:00
$statusTexts = array ( E_MESSAGE_SUCCESS => 'Success' , E_MESSAGE_ERROR => 'Fail' , E_MESSAGE_INFO => 'Info' );
if ( isset ( $pref [ 'forum_user_customtitle' ]) && ! isset ( $pref [ 'signup_option_customtitle' ]))
{
2013-05-12 20:56:35 -07:00
if ( $just_check ) return update_needed ( 'pref: forum_user_customtitle needs to be renamed' );
2010-04-20 21:35:20 +00:00
$pref [ 'signup_option_customtitle' ] = $pref [ 'forum_user_customtitle' ];
unset ( $pref [ 'forum_user_customtitle' ]);
2012-12-03 15:04:11 -08:00
$log -> logMessage ( LAN_UPDATE_20 . 'customtitle' , E_MESSAGE_SUCCESS );
2010-04-20 21:35:20 +00:00
$do_save = TRUE ;
}
// convert all serialized core prefs to e107 ArrayStorage;
$serialz_qry = " SUBSTRING( e107_value,1,5)!='array' AND e107_value !='' " ;
$serialz_qry .= " AND e107_name IN ( " . implode ( " , " , $serialized_prefs ) . " ) " ;
2013-04-25 20:05:32 -07:00
if ( e107 :: getDb () -> select ( " core " , " * " , $serialz_qry ))
{
if ( $just_check ) return update_needed ( 'Convert serialized core prefs' );
while ( $row = e107 :: getDb () -> fetch ( MYSQL_ASSOC ))
2010-04-20 21:35:20 +00:00
{
2013-05-12 20:56:35 -07:00
$status = e107 :: getDb ( 'sql2' ) -> update ( 'core' , " e107_value= \" " . convert_serialized ( $row [ 'e107_value' ]) . " \" WHERE e107_name=' " . $row [ 'e107_name' ] . " ' " ) ? E_MESSAGE_SUCCESS : E_MESSAGE_ERROR ;
$log -> addDebug ( LAN_UPDATE_22 . $row [ 'e107_name' ] . " : " . $status );
2010-04-20 21:35:20 +00:00
}
2013-04-25 20:05:32 -07:00
}
if ( e107 :: getDb () -> select ( " core " , " * " , " e107_name='pm_prefs' LIMIT 1 " ))
{
if ( $just_check ) return update_needed ( 'Rename the pm prefs' );
2013-05-24 22:40:10 +03:00
e107 :: getDb () -> update ( " core " , " e107_name='plugin_pm' WHERE e107_name = 'pm_prefs' " );
2013-04-25 20:05:32 -07:00
}
2010-04-20 21:35:20 +00:00
2010-10-21 17:42:03 +00:00
//@TODO de-serialize the user_prefs also.
2010-04-20 21:35:20 +00:00
// Move the maximum online counts from menu prefs to a separate pref - 'history'
2013-03-28 00:41:29 -07:00
e107 :: getCache () -> clearAll ( 'system' );
$menuConfig = e107 :: getConfig ( 'menu' , true , true );
2010-04-20 21:35:20 +00:00
if ( $menuConfig -> get ( 'most_members_online' ) || $menuConfig -> get ( 'most_guests_online' ) || $menuConfig -> get ( 'most_online_datestamp' ))
{
2012-12-07 15:16:42 -08:00
$status = E_MESSAGE_DEBUG ;
2010-04-20 21:35:20 +00:00
if ( $just_check ) return update_needed ( 'Move online counts from menupref' );
$newPrefs = e107 :: getConfig ( 'history' );
foreach ( array ( 'most_members_online' , 'most_guests_online' , 'most_online_datestamp' ) as $v )
{
if ( FALSE === $newPrefs -> get ( $v , FALSE ))
{
if ( FALSE !== $menuConfig -> get ( $v , FALSE ))
{
$newPrefs -> set ( $v , $menuConfig -> get ( $v ));
}
else
{
$newPrefs -> set ( $v , 0 );
}
}
$menuConfig -> remove ( $v );
}
$result = $newPrefs -> save ( false , true , false );
if ( $result === TRUE )
{
$resultMessage = 'Historic member counts updated' ;
2013-03-28 00:41:29 -07:00
$result = $menuConfig -> save ( false , true , false ); // Only re-save if successul.
2010-04-20 21:35:20 +00:00
}
elseif ( $result === FALSE )
{
$resultMessage = 'moving historic member counts' ;
$status = E_MESSAGE_ERROR ;
}
else
{ // No change
$resultMessage = 'Historic member counts already updated' ;
$status = E_MESSAGE_INFO ;
}
2013-03-28 00:41:29 -07:00
// $result = $menuConfig->save(false, true, false); // Save updated menuprefs - without the counts - don't delete them if it fails.
2010-04-20 21:35:20 +00:00
//$updateMessages[] = $statusTexts[$status].': '.$resultMessage; // Admin log message
2012-12-03 15:04:11 -08:00
$log -> logMessage ( $resultMessage , $status ); // User message
2010-04-20 21:35:20 +00:00
}
2013-05-12 20:56:35 -07:00
2010-04-20 21:35:20 +00:00
// ++++++++ Modify Menu Paths +++++++.
if ( varset ( $changeMenuPaths ))
{
foreach ( $changeMenuPaths as $val )
{
$qry = " SELECT menu_path FROM `#menus` WHERE menu_name = ' " . $val [ 'menu' ] . " ' AND (menu_path=' " . $val [ 'oldpath' ] . " ' || menu_path=' " . $val [ 'oldpath' ] . " /' ) LIMIT 1 " ;
2013-03-09 15:09:33 -08:00
if ( $sql -> gen ( $qry ))
2010-04-20 21:35:20 +00:00
{
if ( $just_check ) return update_needed ( 'Menu path changed required: ' . $val [ 'menu' ] . ' ' );
$updqry = " menu_path=' " . $val [ 'newpath' ] . " /' WHERE menu_name = ' " . $val [ 'menu' ] . " ' AND (menu_path=' " . $val [ 'oldpath' ] . " ' || menu_path=' " . $val [ 'oldpath' ] . " /' ) " ;
2013-03-09 15:09:33 -08:00
$status = $sql -> update ( 'menus' , $updqry ) ? E_MESSAGE_DEBUG : E_MESSAGE_ERROR ;
2012-12-03 15:04:11 -08:00
$log -> logMessage ( LAN_UPDATE_23 . '<b>' . $val [ 'menu' ] . '</b> : ' . $val [ 'oldpath' ] . ' => ' . $val [ 'newpath' ], $status ); // LAN_UPDATE_25;
2010-04-20 21:35:20 +00:00
// catch_error($sql);
}
}
}
// Leave this one here.. just in case..
//delete record for online_extended_menu (now only using one online menu)
if ( $sql -> db_Select ( 'menus' , '*' , " menu_path='online_extended_menu' || menu_path='online_extended_menu/' " ))
{
2012-04-26 10:14:43 +00:00
if ( $just_check ) return update_needed ( " The Menu table needs to have some paths corrected in its data. " );
2010-04-20 21:35:20 +00:00
$row = $sql -> db_Fetch ();
//if online_extended is activated, we need to activate the new 'online' menu, and delete this record
if ( $row [ 'menu_location' ] != 0 )
{
2013-03-09 15:09:33 -08:00
$status = $sql -> update ( 'menus' , " menu_name='online_menu', menu_path='online/' WHERE menu_path='online_extended_menu' || menu_path='online_extended_menu/' " ) ? E_MESSAGE_DEBUG : E_MESSAGE_ERROR ;
2012-12-03 15:04:11 -08:00
$log -> logMessage ( LAN_UPDATE_23 . " <b>online_menu</b> : online/ " , $status );
2010-04-20 21:35:20 +00:00
}
else
{ //else if the menu is not active
//we need to delete the online_extended menu row, and change the online_menu to online
2013-03-09 15:09:33 -08:00
$sql -> delete ( 'menus' , " menu_path='online_extended_menu' || menu_path='online_extended_menu/' " );
2012-12-07 11:55:21 -08:00
$log -> logMessage ( LAN_UPDATE_31 , E_MESSAGE_DEBUG );
2010-04-20 21:35:20 +00:00
}
catch_error ( $sql );
}
//change menu_path for online_menu (if it still exists)
if ( $sql -> db_Select ( 'menus' , 'menu_path' , " menu_path='online_menu' || menu_path='online_menu/' " ))
{
2013-03-27 19:34:45 -07:00
if ( $just_check ) return update_needed ( 'change menu_path for online menu' );
2010-04-20 21:35:20 +00:00
2013-03-09 15:09:33 -08:00
$status = $sql -> update ( 'menus' , " menu_path='online/' WHERE menu_path='online_menu' || menu_path='online_menu/' " ) ? E_MESSAGE_DEBUG : E_MESSAGE_ERROR ;
2012-12-03 15:04:11 -08:00
$log -> logMessage ( LAN_UPDATE_23 . " <b>online_menu</b> : online/ " , $status );
2010-04-20 21:35:20 +00:00
catch_error ( $sql );
}
2012-04-26 10:14:43 +00:00
if ( ! $just_check )
{
// Alert Admin to delete deprecated menu folders.
$chgPath = array ();
foreach ( $changeMenuPaths as $cgpArray )
{
if ( is_dir ( e_PLUGIN . $cgpArray [ 'oldpath' ]))
{
2013-05-05 14:09:50 -07:00
if ( ! in_array ( $cgpArray [ 'oldpath' ], $chgPath ))
{
$chgPath [] = $cgpArray [ 'oldpath' ];
}
2012-04-26 10:14:43 +00:00
}
}
//TODO LAN
if ( count ( $chgPath ))
{
2013-05-12 20:56:35 -07:00
$log -> addWarning ( 'Before continuing, please manually delete the following outdated folders from your system: ' );
2012-04-26 10:14:43 +00:00
array_unique ( $chgPath );
asort ( $chgPath );
foreach ( $chgPath as $cgp )
{
2013-05-12 20:56:35 -07:00
$log -> addWarning ( e_PLUGIN_ABS . " <b> " . $cgp . " </b> " );
2012-04-26 10:14:43 +00:00
}
}
}
2012-07-23 09:35:32 +00:00
2010-04-20 21:35:20 +00:00
//---------------------------------------------------------
// Comments - split user field
//---------------------------------------------------------
if ( $sql -> db_Field ( 'comments' , 'comment_author' ))
{
if ( $just_check ) return update_needed ( 'Comment table author field update' );
if (( ! $sql -> db_Field ( 'comments' , 'comment_author_id' )) // Check to see whether new fields already added - maybe data copy failed part way through
2013-03-09 15:09:33 -08:00
&& ( ! $sql -> gen ( " ALTER TABLE `#comments`
2010-04-20 21:35:20 +00:00
ADD COLUMN comment_author_id int ( 10 ) unsigned NOT NULL default '0' AFTER `comment_author` ,
ADD COLUMN comment_author_name varchar ( 100 ) NOT NULL default '' AFTER `comment_author_id` " )))
{
// Flag error
// $commentMessage = LAN_UPDAXXTE_34;
2012-12-03 15:04:11 -08:00
$log -> logMessage ( LAN_UPDATE_21 . " comments " , E_MESSAGE_ERROR );
2010-04-20 21:35:20 +00:00
}
else
{
2013-03-09 15:09:33 -08:00
if ( FALSE === $sql -> update ( 'comments' , " comment_author_id=SUBSTRING_INDEX(`comment_author`,'.',1), comment_author_name=SUBSTRING(`comment_author` FROM POSITION('.' IN `comment_author`)+1) " ))
2010-04-20 21:35:20 +00:00
{
// Flag error
2012-12-03 15:04:11 -08:00
$log -> logMessage ( LAN_UPDATE_21 . 'comments' , E_MESSAGE_ERROR );
2010-04-20 21:35:20 +00:00
}
else
{ // Delete superceded field - comment_author
2013-03-09 15:09:33 -08:00
if ( ! $sql -> gen ( " ALTER TABLE `#comments` DROP COLUMN `comment_author` " ))
2010-04-20 21:35:20 +00:00
{
// Flag error
2012-12-03 15:04:11 -08:00
$log -> logMessage ( LAN_UPDATE_24 . 'comments - comment_author' , E_MESSAGE_ERROR );
2010-04-20 21:35:20 +00:00
}
}
}
2012-12-07 15:16:42 -08:00
$log -> logMessage ( LAN_UPDATE_21 . 'comments' , E_MESSAGE_DEBUG );
2010-04-20 21:35:20 +00:00
}
2013-05-12 20:56:35 -07:00
2010-04-20 21:35:20 +00:00
// Add index to download history
2011-06-15 05:41:06 +00:00
// Deprecated by db-verify-class
2012-12-08 15:52:40 +01:00
// if (FALSE !== ($temp = addIndexToTable('download_requests', 'download_request_datestamp', $just_check, $updateMessages)))
// {
// if ($just_check)
// {
// return update_needed($temp);
// }
2011-06-15 05:41:06 +00:00
// }
2010-04-20 21:35:20 +00:00
// Extra index to tmp table
2011-06-15 05:41:06 +00:00
// Deprecated by db-verify-class
2012-12-08 15:52:40 +01:00
// if (FALSE !== ($temp = addIndexToTable('tmp', 'tmp_time', $just_check, $updateMessages)))
// {
// if ($just_check)
// {
// return update_needed($temp);
// }
2011-06-15 05:41:06 +00:00
// }
2010-04-20 21:35:20 +00:00
// Extra index to rss table (if used)
2011-06-15 05:41:06 +00:00
// Deprecated by db-verify-class
2012-12-08 15:52:40 +01:00
// if (FALSE !== ($temp = addIndexToTable('rss', 'rss_name', $just_check, $updateMessages, TRUE)))
// {
// if ($just_check)
// {
// return update_needed($temp);
// }
2011-06-15 05:41:06 +00:00
// }
2010-04-20 21:35:20 +00:00
// Front page prefs (logic has changed)
2013-05-01 12:56:19 -07:00
if ( ! isset ( $pref [ 'frontpage_force' ])) // Just set basic options; no real method of converting the existing
{
2010-04-20 21:35:20 +00:00
if ( $just_check ) return update_needed ( 'Change front page prefs' );
$pref [ 'frontpage_force' ] = array ( e_UC_PUBLIC => '' );
2013-05-01 12:56:19 -07:00
$fpdef = vartrue ( $pref [ 'frontpage' ][ 'all' ]) == 'index.php' ? 'index.php' : 'news.php' ;
$pref [ 'frontpage' ] = array ( e_UC_PUBLIC => $fpdef );
2010-04-20 21:35:20 +00:00
// $_pdateMessages[] = LAN_UPDATE_38; //FIXME
2012-12-07 11:55:21 -08:00
$log -> logMessage ( LAN_UPDATE_20 . " frontpage " , E_MESSAGE_DEBUG );
2010-04-20 21:35:20 +00:00
$do_save = TRUE ;
}
// Check need for user timezone before we delete the field
if ( varsettrue ( $pref [ 'signup_option_timezone' ]))
{
if ( $sql -> db_Field ( 'user' , 'user_timezone' , '' , TRUE ) && ! $sql -> db_Field ( 'user_extended' , 'user_timezone' , '' , TRUE ))
{
if ( $just_check ) return update_needed ( 'Move user timezone info' );
if ( ! copy_user_timezone ())
{ // Error doing the transfer
//$updateMessages[] = LAN_UPDATE_42;
2012-12-03 15:04:11 -08:00
$log -> logMessage ( LAN_UPDATE_42 , E_MESSAGE_ERROR );
2010-04-20 21:35:20 +00:00
return FALSE ;
}
//$updateMessages[] = LAN_UPDATE_41;
2012-12-07 15:16:42 -08:00
$log -> logMessage ( LAN_UPDATE_41 , E_MESSAGE_DEBUG );
2010-04-20 21:35:20 +00:00
}
}
2011-06-15 05:41:06 +00:00
// Tables defined in core_sql.php to be RENAMED.
2013-03-27 19:34:45 -07:00
2010-04-20 21:35:20 +00:00
// Next bit will be needed only by the brave souls who used an early CVS - probably delete before release
if ( $sql -> db_Table_exists ( 'rl_history' ) && ! $sql -> db_Table_exists ( 'dblog' ))
{
if ( $just_check ) return update_needed ( 'Rename rl_history to dblog' );
2013-03-09 15:09:33 -08:00
$sql -> gen ( 'ALTER TABLE `' . MPREFIX . 'rl_history` RENAME `' . MPREFIX . 'dblog`' );
2010-04-20 21:35:20 +00:00
//$updateMessages[] = LAN_UPDATE_44;
2012-12-07 11:55:21 -08:00
$log -> logMessage ( LAN_UPDATE_44 , E_MESSAGE_DEBUG );
2010-04-20 21:35:20 +00:00
catch_error ( $sql );
2013-03-27 19:34:45 -07:00
}
//---------------------------------
if ( $sql -> db_Table_exists ( 'dblog' ) && ! $sql -> db_Table_exists ( 'admin_log' ))
{
if ( $just_check ) return update_needed ( 'Rename dblog to admin_log' );
$sql -> gen ( 'ALTER TABLE `' . MPREFIX . 'dblog` RENAME `' . MPREFIX . 'admin_log`' );
catch_error ( $sql );
//$updateMessages[] = LAN_UPDATE_43;
$log -> logMessage ( LAN_UPDATE_43 , E_MESSAGE_DEBUG );
2010-04-20 21:35:20 +00:00
}
2013-03-27 19:34:45 -07:00
2010-04-20 21:35:20 +00:00
// New tables required (list at top. Definitions in core_sql.php)
2011-06-15 05:41:06 +00:00
// ALL DEPRECATED by db_verify class.. see below.
/*
2010-04-20 21:35:20 +00:00
foreach ( $new_tables as $nt )
{
if ( ! $sql -> db_Table_exists ( $nt ))
{
if ( $just_check ) return update_needed ( 'Add table: ' . $nt );
// Get the definition
$defs = $db_parser -> get_table_def ( $nt , e_ADMIN . 'sql/core_sql.php' );
if ( count ( $defs )) // **** Add in table here
{
2013-03-09 15:09:33 -08:00
$status = $sql -> gen ( 'CREATE TABLE `' . MPREFIX . $defs [ 0 ][ 1 ] . '` (' . $defs [ 0 ][ 2 ] . ') TYPE=' . $defs [ 0 ][ 3 ]) ? E_MESSAGE_SUCCESS : E_MESSAGE_ERROR ;
2010-04-20 21:35:20 +00:00
// $updateMessages[] = LAN_UPDATE_45.$defs[0][1];
2012-12-03 15:04:11 -08:00
$log -> logMessage ( LAN_UPDATE_27 . $defs [ 0 ][ 1 ], $status );
2010-04-20 21:35:20 +00:00
// catch_error($sql);
}
else
{ // error parsing defs file
2012-12-03 15:04:11 -08:00
$log -> logMessage ( LAN_UPDATE_46 . $defs [ 0 ][ 1 ], E_MESSAGE_ERROR );
2010-04-20 21:35:20 +00:00
}
unset ( $defs );
}
}
2011-06-15 05:41:06 +00:00
2010-04-20 21:35:20 +00:00
// Tables whose definition needs changing significantly
$debugLevel = E107_DBG_SQLDETAILS ;
foreach ( $changed_tables as $ct )
{
$req_defs = $db_parser -> get_table_def ( $ct , e_ADMIN . " sql/core_sql.php " );
$req_fields = $db_parser -> parse_field_defs ( $req_defs [ 0 ][ 2 ]); // Required definitions
if ( $debugLevel )
{
2012-12-03 15:04:11 -08:00
$log -> logMessage ( " Required table structure: <br /> " . $db_parser -> make_field_list ( $req_fields ), E_MESSAGE_DEBUG );
2010-04-20 21:35:20 +00:00
}
if ((( $actual_defs = $db_parser -> get_current_table ( $ct )) === FALSE ) || ! is_array ( $actual_defs )) // Adds current default prefix
{
2012-12-03 15:04:11 -08:00
$log -> logMessage ( " Couldn't get table structure: " . $ct , E_MESSAGE_DEBUG );
2010-04-20 21:35:20 +00:00
}
else
{
// echo $db_parser->make_table_list($actual_defs);
$actual_fields = $db_parser -> parse_field_defs ( $actual_defs [ 0 ][ 2 ]);
if ( $debugLevel )
{
2012-12-03 15:04:11 -08:00
$log -> logMessage ( " Actual table structure: <br /> " . $db_parser -> make_field_list ( $actual_fields ), E_MESSAGE_DEBUG );
2010-04-20 21:35:20 +00:00
}
$diffs = $db_parser -> compare_field_lists ( $req_fields , $actual_fields );
if ( count ( $diffs [ 0 ]))
{ // Changes needed
if ( $just_check ) return update_needed ( " Field changes rqd; table: " . $ct );
// Do the changes here
if ( $debugLevel )
{
2012-12-03 15:04:11 -08:00
$log -> logMessage ( " List of changes found:<br /> " . $db_parser -> make_changes_list ( $diffs ), E_MESSAGE_DEBUG );
2010-04-20 21:35:20 +00:00
}
$qry = 'ALTER TABLE ' . MPREFIX . $ct . ' ' . implode ( ', ' , $diffs [ 1 ]);
if ( $debugLevel )
{
2012-12-03 15:04:11 -08:00
$log -> logMessage ( " Update Query used: " . $qry , E_MESSAGE_DEBUG );
2010-04-20 21:35:20 +00:00
}
2013-03-09 15:09:33 -08:00
$status = $sql -> gen ( $qry ) ? E_MESSAGE_SUCCESS : E_MESSAGE_ERROR ;
2012-12-03 15:04:11 -08:00
$log -> logMessage ( LAN_UPDATE_21 . $ct , $status );
2010-04-20 21:35:20 +00:00
catch_error ( $sql );
}
}
}
// Plugin tables whose definition needs changing significantly
foreach ( $pluginChangedTables as $plugName => $plugList )
{
if ( plugInstalled ( $plugName ))
{
$ttc = explode ( ',' , $plugList );
foreach ( $ttc as $ct )
{
$sqlDefs = e_PLUGIN . $plugName . '/' . str_replace ( '_menu' , '' , $plugName ) . '_sql.php' ; // Filename containing definitions
// echo "Looking at file: {$sqlDefs}, table {$ct}<br />";
$req_defs = $db_parser -> get_table_def ( $ct , $sqlDefs );
if ( ! is_array ( $req_defs ))
{
echo " Couldn't get definitions from file { $sqlDefs } <br /> " ;
continue ;
}
$req_fields = $db_parser -> parse_field_defs ( $req_defs [ 0 ][ 2 ]); // Required definitions
if ( E107_DBG_SQLDETAILS )
{
$message = " Required plugin table structure: <br /> " . $db_parser -> make_field_list ( $req_fields );
2012-12-03 15:04:11 -08:00
$log -> logMessage ( $message , E_MESSAGE_DEBUG );
2010-04-20 21:35:20 +00:00
}
if ((( $actual_defs = $db_parser -> get_current_table ( $ct )) === FALSE ) || ! is_array ( $actual_defs )) // Adds current default prefix
{
// echo "Couldn't get table structure: {$ct}<br />";
}
else
{
// echo $db_parser->make_table_list($actual_defs);
$actual_fields = $db_parser -> parse_field_defs ( $actual_defs [ 0 ][ 2 ]);
if ( E107_DBG_SQLDETAILS )
{
$message = " Actual table structure: <br /> " . $db_parser -> make_field_list ( $actual_fields );
2012-12-03 15:04:11 -08:00
$log -> logMessage ( $message , E_MESSAGE_DEBUG );
2010-04-20 21:35:20 +00:00
}
$diffs = $db_parser -> compare_field_lists ( $req_fields , $actual_fields );
if ( count ( $diffs [ 0 ]))
{ // Changes needed
if ( E107_DBG_SQLDETAILS )
{
$message = " List of changes found:<br /> " . $db_parser -> make_changes_list ( $diffs );
2012-12-03 15:04:11 -08:00
$log -> logMessage ( $message , E_MESSAGE_DEBUG );
2010-04-20 21:35:20 +00:00
}
if ( $just_check ) return update_needed ( " Field changes rqd; plugin table: " . $ct );
// Do the changes here
$qry = 'ALTER TABLE ' . MPREFIX . $ct . ' ' . implode ( ', ' , $diffs [ 1 ]);
if ( E107_DBG_SQLDETAILS )
{
$message = " Update Query used: " . $qry . " <br /> " ;
2012-12-03 15:04:11 -08:00
$log -> logMessage ( $message , E_MESSAGE_DEBUG );
2010-04-20 21:35:20 +00:00
}
2013-03-09 15:09:33 -08:00
$sql -> gen ( $qry );
2010-04-20 21:35:20 +00:00
$updateMessages [] = LAN_UPDATE_51 . $ct ;
2012-12-03 15:04:11 -08:00
$log -> logMessage ( LAN_UPDATE_51 . $ct , E_MESSAGE_SUCCESS );
2010-04-20 21:35:20 +00:00
catch_error ( $sql );
}
}
}
}
}
2011-06-15 05:41:06 +00:00
*/
2013-03-27 19:34:45 -07:00
2010-04-20 21:35:20 +00:00
// Obsolete tables (list at top)
2013-03-27 19:34:45 -07:00
$sql -> mySQLtableList = false ; // clear the cached table list.
2010-04-20 21:35:20 +00:00
foreach ( $obs_tables as $ot )
{
if ( $sql -> db_Table_exists ( $ot ))
{
if ( $just_check ) return update_needed ( " Delete table: " . $ot );
2013-03-27 19:34:45 -07:00
2013-03-09 15:09:33 -08:00
$status = $sql -> gen ( 'DROP TABLE `' . MPREFIX . $ot . '`' ) ? E_MESSAGE_DEBUG : E_MESSAGE_ERROR ;
2012-12-03 15:04:11 -08:00
$log -> logMessage ( LAN_UPDATE_25 . $ot , $status );
2010-04-20 21:35:20 +00:00
}
}
2013-05-12 20:56:35 -07:00
2010-04-20 21:35:20 +00:00
// Tables where IP address field needs updating to accommodate IPV6
// Set to varchar(45) - just in case something uses the IPV4 subnet (see http://en.wikipedia.org/wiki/IPV6#Notation)
foreach ( $ip_upgrade as $t => $f )
{
if ( $sql -> db_Table_exists ( $t ))
{ // Check for table - might add some core plugin tables in here
if ( $field_info = ( $sql -> db_Field ( $t , $f , '' , TRUE )))
{
if ( strtolower ( $field_info [ 'Type' ]) != 'varchar(45)' )
{
if ( $just_check ) return update_needed ( 'Update IP address field ' . $f . ' in table ' . $t );
2013-03-09 15:09:33 -08:00
$status = $sql -> gen ( " ALTER TABLE ` " . MPREFIX . $t . " ` MODIFY ` { $f } ` VARCHAR(45) NOT NULL DEFAULT ''; " ) ? E_MESSAGE_DEBUG : E_MESSAGE_ERROR ;
2012-12-03 15:04:11 -08:00
$log -> logMessage ( LAN_UPDATE_26 . $t . ' - ' . $f , $status );
2010-04-20 21:35:20 +00:00
// catch_error($sql);
}
}
else
{
// Got a strange error here
}
}
}
2010-10-21 17:42:03 +00:00
2012-12-07 15:16:42 -08:00
2010-10-21 17:42:03 +00:00
2010-04-20 21:35:20 +00:00
// Obsolete prefs (list at top)
// Intentionally do this last - we may check some of them during the update
$accum = array ();
foreach ( $obs_prefs as $p )
{
if ( isset ( $pref [ $p ]))
{
if ( $just_check ) return update_needed ( 'Remove obsolete prefs' );
unset ( $pref [ $p ]);
$do_save = TRUE ;
2013-05-12 20:56:35 -07:00
$log -> addDebug ( 'Removed obsolete pref: ' . $p );
// $accum[] = $p;
2010-04-20 21:35:20 +00:00
}
}
2011-06-15 05:41:06 +00:00
/* -------------- Upgrade Entire Table Structure - Multi-Language Supported ----------------- */
2013-03-09 14:53:01 -08:00
// ONLY ever add fields, never deletes.
2011-06-15 05:41:06 +00:00
require_once ( e_HANDLER . " db_verify_class.php " );
$dbv = new db_verify ;
2013-04-15 19:46:35 -07:00
if ( $plugUpgradeReq = e107 :: getPlugin () -> updateRequired ())
{
$exclude = array_keys ( $plugUpgradeReq ); // search xxxxx_setup.php and check for 'upgrade_required()' == true.
}
else
{
$exclude = false ;
}
2013-03-10 18:42:54 -07:00
$dbv -> compareAll ( $exclude ); // core & plugins, but not plugins calling for an update with xxxxx_setup.php
2011-06-15 05:41:06 +00:00
if ( count ( $dbv -> errors ))
{
2012-12-03 15:04:11 -08:00
if ( $just_check )
{
$mes = e107 :: getMessage ();
2013-05-12 20:56:35 -07:00
$log -> addDebug ( print_a ( $dbv -> errors , true ));
2012-12-03 15:04:11 -08:00
return update_needed ( " Database Tables require updating. " );
}
2013-03-10 18:42:54 -07:00
$dbv -> compileResults ();
$dbv -> runFix (); // Fix entire core database structure and plugins too.
2011-06-15 05:41:06 +00:00
}
2013-03-10 18:42:54 -07:00
2011-06-15 05:41:06 +00:00
// print_a($dbv->results);
// print_a($dbv->fixList);
2013-03-10 18:42:54 -07:00
2011-06-15 05:41:06 +00:00
//TODO - send notification messages to Log.
2013-04-11 13:42:57 -07:00
2013-03-06 23:01:16 -08:00
2013-03-10 18:42:54 -07:00
if ( $sql -> field ( 'page' , 'page_theme' ) && $sql -> gen ( " SELECT * FROM #page WHERE page_theme != '' AND menu_title = '' LIMIT 1 " ))
2013-03-06 23:01:16 -08:00
{
if ( $just_check )
{
return update_needed ( " Pages/Menus Table requires updating. " );
}
2013-03-17 15:25:02 -07:00
if ( $sql -> update ( 'page' , " menu_name = page_theme, menu_title = page_title, menu_text = page_text, menu_template='default', page_title = '', page_text = '' WHERE page_theme !='' AND menu_title = '' AND menu_text = '' " ))
2013-03-06 23:01:16 -08:00
{
2013-03-09 14:53:01 -08:00
$sql -> gen ( " ALTER TABLE `#page` DROP `page_theme` " );
2013-03-07 05:44:49 -08:00
$mes = e107 :: getMessage ();
2013-05-12 20:56:35 -07:00
$log -> addDebug ( " Successfully updated pages/menus table to new format. " );
2013-03-06 23:01:16 -08:00
}
}
2012-12-07 15:16:42 -08:00
2013-04-11 13:42:57 -07:00
if ( $sql -> field ( 'plugin' , 'plugin_releaseUrl' ))
{
if ( $just_check ) return update_needed ( 'plugin_releaseUrl is deprecated and needs to be removed. ' );
if ( $sql -> gen ( " ALTER TABLE `#plugin` DROP `plugin_releaseUrl` " ))
{
2013-05-12 20:56:35 -07:00
$log -> addDebug ( " Successfully removed plugin_releaseUrl. " );
2013-04-11 13:42:57 -07:00
}
}
2013-05-12 20:56:35 -07:00
2012-12-07 15:16:42 -08:00
// --- Notify Prefs
2013-03-27 19:34:45 -07:00
// $notify_prefs = $sysprefs -> get('notify_prefs');
// $notify_prefs = $eArrayStorage -> ReadArray($notify_prefs);
e107 :: getCache () -> clearAll ( 'system' );
2013-05-12 20:56:35 -07:00
2013-03-27 19:34:45 -07:00
$notify_prefs = e107 :: getConfig ( 'notify' , true , true ) -> getPref ();
2011-06-15 05:41:06 +00:00
2012-12-07 15:16:42 -08:00
$nt_changed = 0 ;
if ( vartrue ( $notify_prefs [ 'event' ]))
{
foreach ( $notify_prefs [ 'event' ] as $e => $d )
{
if ( isset ( $d [ 'type' ]))
{
if ( $just_check ) return update_needed ( 'Notify pref: ' . $e . ' outdated' );
switch ( $d [ 'type' ])
{
case 'main' :
$notify_prefs [ 'event' ][ $e ][ 'class' ] = e_UC_MAINADMIN ;
break ;
case 'class' : // Should already have class defined
break ;
case 'email' :
$notify_prefs [ 'event' ][ $e ][ 'class' ] = 'email' ;
break ;
case 'off' : // Need to disable
default :
$notify_prefs [ 'event' ][ $e ][ 'class' ] = e_UC_NOBODY ; // Just disable if we don't know what else to do
}
$nt_changed ++ ;
2013-06-18 20:21:10 -07:00
$notify_prefs [ 'event' ][ $e ][ 'legacy' ] = 1 ;
2012-12-07 15:16:42 -08:00
unset ( $notify_prefs [ 'event' ][ $e ][ 'type' ]);
}
}
}
2013-03-27 19:34:45 -07:00
2012-12-07 15:16:42 -08:00
if ( $nt_changed )
{
$s_prefs = $tp -> toDB ( $notify_prefs );
$s_prefs = $eArrayStorage -> WriteArray ( $s_prefs );
// Could we use $sysprefs->set($s_prefs,'notify_prefs') instead - avoids caching problems ????
2013-03-09 15:09:33 -08:00
$status = ( $sql -> update ( " core " , " e107_value=' " . $s_prefs . " ' WHERE e107_name='notify_prefs' " ) !== FALSE ) ? E_MESSAGE_DEBUG : E_MESSAGE_ERROR ;
2012-12-07 15:16:42 -08:00
$message = str_replace ( '--COUNT--' , $nt_changed , LAN_UPDATE_20 );
$log -> logMessage ( $message , $status );
}
2013-03-27 19:34:45 -07:00
2012-12-07 15:16:42 -08:00
2013-05-12 20:56:35 -07:00
2012-12-07 15:16:42 -08:00
// --------------- Saved emails - copy across
if ( ! $just_check && $sql -> db_Select ( 'generic' , '*' , " gen_type='massmail' " ))
{
if ( $just_check ) return update_needed ( 'Copy across saved emails' );
require_once ( e_HANDLER . 'mail_manager_class.php' );
$mailHandler = new e107MailManager ;
$i = 0 ;
while ( $row = $sql -> db_Fetch ( MYSQL_ASSOC ))
{
$mailRecord = array (
'mail_create_date' => $row [ 'gen_datestamp' ],
'mail_creator' => $row [ 'gen_user_id' ],
'mail_title' => $row [ 'gen_ip' ],
'mail_subject' => $row [ 'gen_ip' ],
'mail_body' => $row [ 'gen_chardata' ],
'mail_content_status' => MAIL_STATUS_SAVED
);
$mailHandler -> mailtoDb ( $mailRecord , TRUE );
$mailHandler -> saveEmail ( $mailRecord , TRUE );
2013-03-09 15:09:33 -08:00
$sql2 -> delete ( 'generic' , 'gen_id=' . intval ( $row [ 'gen_id' ])); // Delete as we go in case operation fails part way through
2012-12-07 15:16:42 -08:00
$i ++ ;
}
unset ( $mailHandler );
$log -> logMessage ( str_replace ( '--COUNT--' , $i , LAN_UPDATE_28 ));
}
2013-05-12 20:56:35 -07:00
2011-06-15 05:41:06 +00:00
// ------------------- Populate Plugin Table With Changes ------------------
2013-02-11 14:56:43 +02:00
if ( ! isset ( $pref [ 'shortcode_legacy_list' ]))
{
if ( $just_check ) return update_needed ( 'Legacy shortcode conversion' );
// Reset, legacy and new shortcode list will be generated in plugin update routine
$pref [ 'shortcode_legacy_list' ] = array ();
$pref [ 'shortcode_list' ] = array ();
2013-05-12 20:56:35 -07:00
save_prefs ();
2013-02-11 14:56:43 +02:00
$ep = e107 :: getPlugin ();
$ep -> update_plugins_table ( $mode ); // scan for e_xxx changes and save to plugin table.
$ep -> save_addon_prefs ( $mode ); // generate global e_xxx_list prefs from plugin table.
}
2013-05-12 20:56:35 -07:00
2011-06-15 05:41:06 +00:00
// This has to be done after the table is upgraded
2013-05-12 20:56:35 -07:00
if ( $sql -> select ( 'plugin' , 'plugin_category' , " plugin_category = '' " ))
2011-06-15 05:41:06 +00:00
{
if ( $just_check ) return update_needed ( 'Update plugin table' );
require_once ( e_HANDLER . 'plugin_class.php' );
$ep = new e107plugin ;
2013-05-12 20:56:35 -07:00
$ep -> update_plugins_table ( 'update' );
2011-06-15 05:41:06 +00:00
// $_pdateMessages[] = LAN_UPDATE_XX24;
// catch_error($sql);
}
2012-12-08 15:52:40 +01:00
2012-06-08 06:03:07 +00:00
//-- Media-manger import --------------------------------------------------
2013-05-12 20:56:35 -07:00
2012-06-08 06:03:07 +00:00
2012-08-19 05:10:43 +00:00
// Autogenerate filetypes.xml if not found.
if ( ! is_readable ( e_SYSTEM . " filetypes.xml " ))
{
$data = ' < ? xml version = " 1.0 " encoding = " utf-8 " ?>
< e107Filetypes >
< class name = " 253 " type = " zip,gz,jpg,jpeg,png,gif,xml " maxupload = " 2M " />
</ e107Filetypes > ' ;
file_put_contents ( e_SYSTEM . " filetypes.xml " , $data );
}
2012-06-08 06:03:07 +00:00
$root_media = str_replace ( basename ( e_MEDIA ) . " / " , " " , e_MEDIA );
2013-04-19 22:50:41 -07:00
$user_media_dirs = array ( " images " , " avatars " , " avatars/default " , " avatars/upload " , " files " , " temp " , " videos " , " icons " );
2012-06-08 06:03:07 +00:00
// check for old paths and rename.
if ( is_dir ( $root_media . " images " ) || is_dir ( $root_media . " temp " ))
{
foreach ( $user_media_dirs as $md )
{
@ rename ( $root_media . $md , e_MEDIA . $md );
}
}
// create sub-directories if they do not exist.
2013-04-19 22:58:57 -07:00
if ( ! is_dir ( e_MEDIA . " images " ) || ! is_dir ( e_MEDIA . " temp " ) || ! is_dir ( e_AVATAR_UPLOAD ) || ! is_dir ( e_AVATAR_DEFAULT ) )
2012-06-08 06:03:07 +00:00
{
foreach ( $user_media_dirs as $md )
{
2012-12-16 14:28:30 -08:00
if ( ! is_dir ( e_MEDIA . $md ))
{
mkdir ( e_MEDIA . $md );
}
2012-06-08 06:03:07 +00:00
}
}
2010-04-20 21:35:20 +00:00
2012-06-17 10:51:13 +00:00
// Move Avatars to new location
$av1 = e107 :: getFile () -> get_files ( e_FILE . 'public/avatars' , '.jpg|.gif|.png|.GIF|.jpeg|.JPG|.PNG' );
$av2 = e107 :: getFile () -> get_files ( e_IMAGE . 'avatars' , '.jpg|.gif|.png|.GIF|.jpeg|.JPG|.PNG' );
$avatar_images = array_merge ( $av1 , $av2 );
if ( count ( $avatar_images ))
{
if ( $just_check ) return update_needed ( 'Avatar paths require updating.' );
foreach ( $avatar_images as $av )
{
2013-04-19 22:50:41 -07:00
$apath = ( strstr ( $av [ 'path' ], 'public/' )) ? e_AVATAR_UPLOAD : e_AVATAR_DEFAULT ;
2013-04-19 14:00:19 -07:00
2013-04-19 22:50:41 -07:00
@ rename ( $av [ 'path' ] . $av [ 'fname' ], $apath . $av [ 'fname' ]);
2012-06-17 10:51:13 +00:00
}
}
// -------------------------------
2012-07-23 09:35:32 +00:00
2014-01-20 06:20:58 -08:00
if ( ! e107 :: isInstalled ( 'download' ) && $sql -> gen ( " SELECT * FROM #links WHERE link_url LIKE 'download.php%' AND link_class != ' " . e_UC_NOBODY . " ' LIMIT 1 " ))
{
if ( $just_check ) return update_needed ( 'Download Plugin needs to be installed.' );
e107 :: getSingleton ( 'e107plugin' ) -> install ( 'download' , array ( 'nolinks' => true ));
2014-01-20 10:21:44 -08:00
// e107::getSingleton('e107plugin')->save_addon_prefs(); //XXX Needed? Uncomment if SQL update does not occur.
2014-01-20 06:20:58 -08:00
}
2012-06-17 10:51:13 +00:00
2014-05-22 14:54:56 -07:00
if ( ! e107 :: isInstalled ( 'banner' ) && $sql -> gen ( " SELECT * FROM #banner LIMIT 1 " ))
{
if ( $just_check ) return update_needed ( 'Banner Table found, but plugin not installed. Needs to be refreshed.' );
e107 :: getSingleton ( 'e107plugin' ) -> refresh ( 'banner' );
// e107::getSingleton('e107plugin')->save_addon_prefs(); //XXX Needed? Uncomment if SQL update does not occur.
}
2014-01-20 06:20:58 -08:00
// ---------------------------------
2012-04-22 06:19:21 +00:00
$med = e107 :: getMedia ();
2010-04-20 21:35:20 +00:00
2012-04-22 06:19:21 +00:00
// Media Category Update
if ( $sql -> db_Field ( " core_media_cat " , " media_cat_nick " ))
{
2013-03-09 15:09:33 -08:00
$count = $sql -> gen ( " SELECT * FROM `#core_media_cat` WHERE media_cat_nick = '_common' " );
2012-04-22 06:19:21 +00:00
if ( $count == 1 )
{
if ( $just_check ) return update_needed ( 'Media-Manager Categories needs to be updated.' );
2013-03-09 15:09:33 -08:00
$sql -> update ( 'core_media_cat' , " media_cat_owner = media_cat_nick, media_cat_category = media_cat_nick WHERE media_cat_nick REGEXP '_common|news|page|_icon_16|_icon_32|_icon_48|_icon_64' " );
$sql -> update ( 'core_media_cat' , " media_cat_owner = '_icon', media_cat_category = media_cat_nick WHERE media_cat_nick REGEXP '_icon_16|_icon_32|_icon_48|_icon_64' " );
$sql -> update ( 'core_media_cat' , " media_cat_owner = 'download', media_cat_category='download_image' WHERE media_cat_nick = 'download' " );
$sql -> update ( 'core_media_cat' , " media_cat_owner = 'download', media_cat_category='download_thumb' WHERE media_cat_nick = 'downloadthumb' " );
$sql -> update ( 'core_media_cat' , " media_cat_owner = 'news', media_cat_category='news_thumb' WHERE media_cat_nick = 'newsthumb' " );
2013-05-12 20:56:35 -07:00
$log -> addDebug ( " core-media-cat Categories and Ownership updated " );
2013-03-27 19:34:45 -07:00
if ( $sql -> gen ( " ALTER TABLE ` " . MPREFIX . " core_media_cat` DROP `media_cat_nick` " ))
2012-04-22 06:19:21 +00:00
{
2013-05-12 20:56:35 -07:00
$log -> addDebug ( " core-media-cat `media_cat_nick` field removed. " );
2012-04-22 06:19:21 +00:00
}
2012-08-19 02:33:43 +00:00
// $query = "INSERT INTO `".MPREFIX."core_media_cat` (`media_cat_id`, `media_cat_owner`, `media_cat_category`, `media_cat_title`, `media_cat_diz`, `media_cat_class`, `media_cat_image`, `media_cat_order`) VALUES
// (0, 'gallery', 'gallery_1', 'Gallery 1', 'Visible to the public at /gallery.php', 0, '', 0);
/// ";
//
// if(mysql_query($query))
// {
2013-05-12 20:56:35 -07:00
// $log->addDebug("Added core-media-cat Gallery.");
2012-08-19 02:33:43 +00:00
// }
2012-04-22 06:19:21 +00:00
}
}
2013-05-12 20:56:35 -07:00
2012-04-22 06:19:21 +00:00
// Media Update
2013-03-09 15:09:33 -08:00
$count = $sql -> gen ( " SELECT * FROM `#core_media` WHERE media_category = 'newsthumb' OR media_category = 'downloadthumb' LIMIT 1 " );
2012-04-22 06:19:21 +00:00
if ( $count == 1 )
{
if ( $just_check ) return update_needed ( 'Media-Manager Data needs to be updated.' );
2013-03-09 15:09:33 -08:00
$sql -> update ( 'core_media' , " media_category='download_image' WHERE media_category = 'download' " );
$sql -> update ( 'core_media' , " media_category='download_thumb' WHERE media_category = 'downloadthumb' " );
$sql -> update ( 'core_media' , " media_category='news_thumb' WHERE media_category = 'newsthumb' " );
2013-05-12 20:56:35 -07:00
$log -> addDebug ( " core-media Category names updated " );
2012-04-22 06:19:21 +00:00
}
2012-05-22 13:32:49 +00:00
// Media Update - core media and core-file.
2013-03-09 15:09:33 -08:00
$count = $sql -> gen ( " SELECT * FROM `#core_media` WHERE media_category = '_common' LIMIT 1 " );
2012-05-22 13:32:49 +00:00
if ( $count == 1 )
{
if ( $just_check ) return update_needed ( 'Media-Manager Category Data needs to be updated.' );
2013-03-09 15:09:33 -08:00
$sql -> update ( 'core_media' , " media_category='_common_image' WHERE media_category = '_common' " );
2013-05-12 20:56:35 -07:00
$log -> addDebug ( " core-media _common Category updated " );
2012-05-22 13:32:49 +00:00
}
2012-04-22 06:19:21 +00:00
2012-05-22 13:32:49 +00:00
// Media Update - core media and core-file. CATEGORY
2013-03-09 15:09:33 -08:00
$count = $sql -> gen ( " SELECT * FROM `#core_media_cat` WHERE media_cat_category = '_common' LIMIT 1 " );
2012-05-22 13:32:49 +00:00
if ( $count == 1 )
{
if ( $just_check ) return update_needed ( 'Media-Manager Category Data needs to be updated.' );
2013-03-09 15:09:33 -08:00
$sql -> update ( 'core_media_cat' , " media_cat_category='_common_image' WHERE media_cat_category = '_common' " );
2013-03-27 19:34:45 -07:00
$sql -> gen ( " INSERT INTO ` " . MPREFIX . " core_media_cat` VALUES(0, '_common', '_common_file', '(Common Area)', 'Media in this category will be available in all areas of admin. ', 253, '', 0); " );
$sql -> gen ( " INSERT INTO ` " . MPREFIX . " core_media_cat` VALUES(0, 'download', 'download_file', 'Download Files', '', 253, '', 0); " );
2013-05-12 20:56:35 -07:00
$log -> addDebug ( " core-media-cat _common Category updated " );
2012-05-22 13:32:49 +00:00
}
2013-03-27 19:34:45 -07:00
2013-03-09 15:09:33 -08:00
$count = $sql -> gen ( " SELECT * FROM `#core_media_cat` WHERE `media_cat_owner` = '_common' LIMIT 1 " );
2012-12-08 15:52:40 +01:00
if ( $count != 1 )
2010-04-20 21:35:20 +00:00
{
2011-07-25 02:41:49 +00:00
if ( $just_check ) return update_needed ( 'Add Media-Manager Categories and Import existing images.' );
2010-04-20 21:35:20 +00:00
2013-03-28 00:41:29 -07:00
$e107_core_media_cat = array (
array ( 'media_cat_id' => 0 , 'media_cat_owner' => '_common' , 'media_cat_category' => '_common_image' , 'media_cat_title' => '(Common Images)' , 'media_cat_sef' => '' , 'media_cat_diz' => 'Media in this category will be available in all areas of admin.' , 'media_cat_class' => '253' , 'media_cat_image' => '' , 'media_cat_order' => '0' ),
array ( 'media_cat_id' => 0 , 'media_cat_owner' => '_common' , 'media_cat_category' => '_common_file' , 'media_cat_title' => '(Common Files)' , 'media_cat_sef' => '' , 'media_cat_diz' => 'Media in this category will be available in all areas of admin.' , 'media_cat_class' => '253' , 'media_cat_image' => '' , 'media_cat_order' => '0' ),
array ( 'media_cat_id' => 0 , 'media_cat_owner' => 'news' , 'media_cat_category' => 'news' , 'media_cat_title' => 'News' , 'media_cat_sef' => '' , 'media_cat_diz' => 'Will be available in the news area.' , 'media_cat_class' => '253' , 'media_cat_image' => '' , 'media_cat_order' => '1' ),
array ( 'media_cat_id' => 0 , 'media_cat_owner' => 'page' , 'media_cat_category' => 'page' , 'media_cat_title' => 'Custom Pages' , 'media_cat_sef' => '' , 'media_cat_diz' => 'Will be available in the custom pages area of admin.' , 'media_cat_class' => '253' , 'media_cat_image' => '' , 'media_cat_order' => '0' ),
array ( 'media_cat_id' => 0 , 'media_cat_owner' => 'download' , 'media_cat_category' => 'download_image' , 'media_cat_title' => 'Download Images' , 'media_cat_sef' => '' , 'media_cat_diz' => '' , 'media_cat_class' => '253' , 'media_cat_image' => '' , 'media_cat_order' => '0' ),
array ( 'media_cat_id' => 0 , 'media_cat_owner' => 'download' , 'media_cat_category' => 'download_thumb' , 'media_cat_title' => 'Download Thumbnails' , 'media_cat_sef' => '' , 'media_cat_diz' => '' , 'media_cat_class' => '253' , 'media_cat_image' => '' , 'media_cat_order' => '0' ),
array ( 'media_cat_id' => 0 , 'media_cat_owner' => 'download' , 'media_cat_category' => 'download_file' , 'media_cat_title' => 'Download Files' , 'media_cat_sef' => '' , 'media_cat_diz' => '' , 'media_cat_class' => '253' , 'media_cat_image' => '' , 'media_cat_order' => '0' ),
array ( 'media_cat_id' => 0 , 'media_cat_owner' => 'news' , 'media_cat_category' => 'news_thumb' , 'media_cat_title' => 'News Thumbnails (Legacy)' , 'media_cat_sef' => '' , 'media_cat_diz' => 'Legacy news thumbnails.' , 'media_cat_class' => '253' , 'media_cat_image' => '' , 'media_cat_order' => '1' ),
);
foreach ( $e107_core_media_cat as $insert )
{
$sql -> insert ( 'core_media_cat' , $insert );
}
2012-04-26 01:33:33 +00:00
2013-03-28 00:41:29 -07:00
// $sql->gen("INSERT INTO `".MPREFIX."core_media_cat` VALUES(0, '_common', '_common_image', '(Common Images)', '', 'Media in this category will be available in all areas of admin. ', 253, '', 1);");
// $sql->gen("INSERT INTO `".MPREFIX."core_media_cat` VALUES(0, '_common', '_common_file', '(Common Files)', '', 'Media in this category will be available in all areas of admin. ', 253, '', 2);");
2012-05-22 13:32:49 +00:00
2013-03-28 00:41:29 -07:00
// $sql->gen("INSERT INTO `".MPREFIX."core_media_cat` VALUES(0, 'news', 'news', 'News', '', 'Will be available in the news area. ', 253, '', 3);");
// $sql->gen("INSERT INTO `".MPREFIX."core_media_cat` VALUES(0, 'page', 'page', 'Custom Pages', '', 'Will be available in the custom pages area of admin. ', 253, '', 4);");
2012-05-22 13:32:49 +00:00
2013-03-28 00:41:29 -07:00
// $sql->gen("INSERT INTO `".MPREFIX."core_media_cat` VALUES(0, 'download', 'download_image','', 'Download Images', '', 253, '', 5);");
// $sql->gen("INSERT INTO `".MPREFIX."core_media_cat` VALUES(0, 'download', 'download_thumb', '', 'Download Thumbnails', '', 253, '', 6);");
// $sql->gen("INSERT INTO `".MPREFIX."core_media_cat` VALUES(0, 'download', 'download_file', '', 'Download Files', '', 253, '', 7);");
2012-05-22 13:32:49 +00:00
2012-08-19 02:33:43 +00:00
// mysql_query("INSERT INTO `".MPREFIX."core_media_cat` VALUES(0, 'gallery', 'gallery_1', 'Gallery', 'Visible to the public at /gallery.php', 0, '', 0);");
2012-05-22 13:32:49 +00:00
2013-03-28 00:41:29 -07:00
// $sql->gen("INSERT INTO `".MPREFIX."core_media_cat` VALUES(0, 'news', 'news_thumb', 'News Thumbnails (Legacy)', '', 'Legacy news thumbnails. ', 253, '', 8);");
2012-04-26 05:41:24 +00:00
2012-04-22 06:19:21 +00:00
$med -> import ( 'news_thumb' , e_IMAGE . 'newspost_images' , " ^thumb_ " );
2012-12-08 15:52:40 +01:00
$med -> import ( 'news' , e_IMAGE . 'newspost_images' );
$med -> import ( 'page' , e_IMAGE . 'custom' );
2012-04-20 07:19:58 +00:00
}
2013-03-27 19:34:45 -07:00
else
{
2013-05-12 20:56:35 -07:00
// $log->addDebug("Media COUNT was ".$count. " LINE: ".__LINE__);
2013-03-27 19:34:45 -07:00
}
2012-04-20 07:19:58 +00:00
// Check for Legacy Download Images.
2012-04-22 06:19:21 +00:00
$fl = e107 :: getFile ();
$dl_images = $fl -> get_files ( e_FILE . 'downloadimages' );
2013-03-09 15:09:33 -08:00
if ( count ( $dl_images ) && ! $sql -> gen ( " SELECT * FROM `#core_media` WHERE `media_category` = 'download_image' " ))
2012-04-20 07:19:58 +00:00
{
if ( $just_check ) return update_needed ( 'Import Download Images into Media Manager' );
2012-04-22 06:19:21 +00:00
$med -> import ( 'download_image' , e_FILE . 'downloadimages' );
$med -> import ( 'download_thumb' , e_FILE . 'downloadthumbs' );
2012-04-20 07:19:58 +00:00
}
2012-07-20 07:42:19 +00:00
$dl_files = $fl -> get_files ( e_FILE . 'downloads' , " " , " standard " , 5 ); // don't use e_DOWNLOAD or a loop may occur.
2013-03-31 00:06:21 -07:00
$publicFilter = array ( '_FT' , '^thumbs\.db$' , '^Thumbs\.db$' , '.*\._$' , '^\.htaccess$' , '^\.cvsignore$' , '^\.ftpquota$' , '^index\.html$' , '^null\.txt$' , '\.bak$' , '^.tmp' ); // Default file filter (regex format)
// $publicFilter = array(1);
$public_files = $fl -> get_files ( e_FILE . 'public' , '' , $publicFilter );
2012-05-25 11:30:49 +00:00
2013-03-09 15:09:33 -08:00
if (( count ( $dl_files ) || count ( $public_files )) && ! $sql -> gen ( " SELECT * FROM `#core_media` WHERE `media_category` = 'download_file' " ))
2012-05-25 11:30:49 +00:00
{
2013-03-31 00:06:21 -07:00
if ( $just_check ) return update_needed ( 'Import ' . count ( $dl_files ) . ' Download File(s) and ' . count ( $public_files ) . ' Public File(s) into Media Manager' );
2012-05-25 11:30:49 +00:00
// check for file-types;
if ( is_readable ( e_ADMIN . 'filetypes.php' ))
{
$a_types = strtolower ( trim ( file_get_contents ( e_ADMIN . 'filetypes.php' )));
$srch = array ( " png " , " jpg " , " jpeg " , " gif " );
$a_types = str_replace ( $srch , " " , $a_types ); // filter-out images.
} else
{
$a_types = 'zip, gz, pdf' ;
}
$a_types = explode ( ',' , $a_types );
foreach ( $a_types as $f_type ) {
$allowed_types [] = trim ( str_replace ( '.' , '' , $f_type ));
}
$fmask = '[a-zA-z0-9_-]+\.(' . implode ( '|' , $allowed_types ) . ')$' ;
$med -> import ( 'download_file' , e_DOWNLOAD , $fmask );
$med -> import ( '_common_file' , e_FILE . 'public' , $fmask );
}
2013-05-12 20:56:35 -07:00
2012-12-08 15:52:40 +01:00
2013-03-09 15:09:33 -08:00
$count = $sql -> gen ( " SELECT * FROM `#core_media_cat` WHERE media_cat_owner='_icon' " );
2010-04-20 21:35:20 +00:00
2012-12-08 15:52:40 +01:00
if ( ! $count )
{
if ( $just_check ) return update_needed ( 'Add icons to media-manager' );
2012-04-22 06:19:21 +00:00
$query = " INSERT INTO ` " . MPREFIX . " core_media_cat` (`media_cat_id`, `media_cat_owner`, `media_cat_category`, `media_cat_title`, `media_cat_diz`, `media_cat_class`, `media_cat_image`, `media_cat_order`) VALUES
( 0 , '_icon' , '_icon_16' , 'Icons 16px' , 'Available where icons are used in admin. ' , 253 , '' , 0 ),
( 0 , '_icon' , '_icon_32' , 'Icons 32px' , 'Available where icons are used in admin. ' , 253 , '' , 0 ),
( 0 , '_icon' , '_icon_48' , 'Icons 48px' , 'Available where icons are used in admin. ' , 253 , '' , 0 ),
( 0 , '_icon' , '_icon_64' , 'Icons 64px' , 'Available where icons are used in admin. ' , 253 , '' , 0 );
2012-12-08 15:52:40 +01:00
" ;
2010-04-20 21:35:20 +00:00
2013-03-27 19:34:45 -07:00
if ( ! $sql -> gen ( $query ))
2012-12-08 15:52:40 +01:00
{
// echo "mysyql error";
// error or already exists.
}
2010-04-20 21:35:20 +00:00
2012-12-08 15:52:40 +01:00
$med -> importIcons ( e_PLUGIN );
2012-04-20 07:19:58 +00:00
$med -> importIcons ( e_IMAGE . " icons/ " );
2012-12-08 15:52:40 +01:00
$med -> importIcons ( e_THEME . $pref [ 'sitetheme' ] . " /images/ " );
2013-05-12 20:56:35 -07:00
$log -> addDebug ( " Icon category added " );
2012-12-08 15:52:40 +01:00
}
// Any other images should be imported manually via Media Manager batch-import.
2010-04-20 21:35:20 +00:00
// ------------------------------------------------------------------
2013-03-28 00:41:29 -07:00
// Check that custompages have been imported from current theme.php file
2013-05-12 20:56:35 -07:00
if ( ! $just_check ) // Running the Upgrade Process.
2013-03-28 00:41:29 -07:00
{
2013-05-25 22:30:10 -07:00
if ( ! is_array ( $pref [ 'sitetheme_layouts' ]) || ! vartrue ( $pref [ 'sitetheme_deflayout' ]))
2013-03-28 00:41:29 -07:00
{
2013-05-25 22:30:10 -07:00
$th = e107 :: getSingleton ( 'themeHandler' );
$tmp = $th -> getThemeInfo ( $pref [ 'sitetheme' ]);
if ( $th -> setTheme ( $pref [ 'sitetheme' ], false ))
{
$log -> addDebug ( " Updated SiteTheme prefs " );
}
else
{
$log -> addDebug ( " Couldn't update SiteTheme prefs " );
}
2013-05-12 20:56:35 -07:00
}
$log -> toFile ( 'upgrade_v1_to_v2' );
if ( $do_save )
{
save_prefs ();
$log -> logMessage ( LAN_UPDATE_50 );
// $log->logMessage(implode(', ', $accum), E_MESSAGE_NODISPLAY);
//$updateMessages[] = LAN_UPDATE_50.implode(', ',$accum); // Note for admin log
2013-03-28 00:41:29 -07:00
}
2013-06-01 03:55:12 -07:00
$log -> flushMessages ( 'UPDATE_01' ); // Write admin log entry, update message handler
2013-05-12 20:56:35 -07:00
}
else
{
2013-06-01 03:55:12 -07:00
$log -> toFile ( 'upgrade_v1_to_v2_check' );
}
2013-03-28 00:41:29 -07:00
2013-05-12 20:56:35 -07:00
2010-04-20 21:35:20 +00:00
2013-06-01 03:55:12 -07:00
2013-05-12 20:56:35 -07:00
2010-04-20 21:35:20 +00:00
2012-12-03 15:04:11 -08:00
//FIXME grab message-stack from $log for the log.
2010-04-20 21:35:20 +00:00
2013-03-27 19:34:45 -07:00
//if ($just_check) return TRUE;
2013-05-12 20:56:35 -07:00
2013-06-01 03:55:12 -07:00
2013-05-12 20:56:35 -07:00
2010-04-20 21:35:20 +00:00
//$admin_log->log_event('UPDATE_01',LAN_UPDATE_14.$e107info['e107_version'].'[!br!]'.implode('[!br!]',$updateMessages),E_LOG_INFORMATIVE,''); // Log result of actual update
return $just_check ;
}
2011-06-15 05:41:06 +00:00
/* No Longed Used I think
2010-04-20 21:35:20 +00:00
function core_media_import ( $cat , $epath )
{
if ( ! vartrue ( $cat )){ return ;}
if ( ! is_readable ( $epath ))
{
return ;
}
$fl = e107 :: getFile ();
$tp = e107 :: getParser ();
$sql = e107 :: getDb ();
$mes = e107 :: getMessage ();
$fl -> setFileInfo ( 'all' );
$img_array = $fl -> get_files ( $epath , '' , '' , 2 );
if ( ! count ( $img_array )){ return ;}
foreach ( $img_array as $f )
{
$fullpath = $tp -> createConstants ( $f [ 'path' ] . $f [ 'fname' ], 1 );
$insert = array (
'media_caption' => $f [ 'fname' ],
'media_description' => '' ,
'media_category' => $cat ,
'media_datestamp' => $f [ 'modified' ],
'media_url' => $fullpath ,
'media_userclass' => 0 ,
'media_name' => $f [ 'fname' ],
'media_author' => USERID ,
'media_size' => $f [ 'fsize' ],
'media_dimensions' => $f [ 'img-width' ] . " x " . $f [ 'img-height' ],
'media_usedby' => '' ,
'media_tags' => '' ,
'media_type' => $f [ 'mime' ]
);
if ( ! $sql -> db_Select ( 'core_media' , 'media_url' , " media_url = ' " . $fullpath . " ' LIMIT 1 " ))
{
if ( $sql -> db_Insert ( " core_media " , $insert ))
{
$mes -> add ( " Importing Media: " . $f [ 'fname' ], E_MESSAGE_SUCCESS );
}
}
}
}
2011-06-15 05:41:06 +00:00
*/
2010-04-20 21:35:20 +00:00
function update_70x_to_706 ( $type = '' )
{
global $sql , $ns , $pref , $e107info , $admin_log , $emessage ;
$just_check = $type == 'do' ? FALSE : TRUE ;
if ( ! $sql -> db_Field ( " plugin " , 5 )) // not plugin_rss so just add the new one.
{
if ( $just_check ) return update_needed ();
$sql -> db_Select_gen ( " ALTER TABLE ` " . MPREFIX . " plugin` ADD `plugin_addons` TEXT NOT NULL ; " );
catch_error ( $sql );
}
//rename plugin_rss field
if ( $sql -> db_Field ( " plugin " , 5 ) == " plugin_rss " )
{
if ( $just_check ) return update_needed ();
$sql -> db_Select_gen ( " ALTER TABLE ` " . MPREFIX . " plugin` CHANGE `plugin_rss` `plugin_addons` TEXT NOT NULL; " );
catch_error ( $sql );
}
if ( $sql -> db_Field ( " dblog " , 5 ) == " dblog_query " )
{
if ( $just_check ) return update_needed ();
$sql -> db_Select_gen ( " ALTER TABLE ` " . MPREFIX . " dblog` CHANGE `dblog_query` `dblog_title` VARCHAR( 255 ) NOT NULL DEFAULT ''; " );
catch_error ( $sql );
$sql -> db_Select_gen ( " ALTER TABLE ` " . MPREFIX . " dblog` CHANGE `dblog_remarks` `dblog_remarks` TEXT NOT NULL; " );
catch_error ( $sql );
}
if ( ! $sql -> db_Field ( " plugin " , " plugin_path " , " UNIQUE " ))
{
if ( $just_check ) return update_needed ();
if ( ! $sql -> db_Select_gen ( " ALTER TABLE ` " . MPREFIX . " plugin` ADD UNIQUE (`plugin_path`); " ))
{
2012-12-03 15:04:11 -08:00
$mesg = LAN_UPDATE_12 . " : <a href=' " . e_ADMIN . " db.php?plugin'> " . ADLAN_145 . " </a>. " ;
2010-04-20 21:35:20 +00:00
//$ns -> tablerender(LAN_ERROR,$mes);
2012-12-03 15:04:11 -08:00
$emessage -> add ( $mesg , E_MESSAGE_ERROR );
2010-04-20 21:35:20 +00:00
catch_error ( $sql );
}
}
if ( ! $sql -> db_Field ( " online " , 6 )) // online_active field
{
if ( $just_check ) return update_needed ();
$sql -> db_Select_gen ( " ALTER TABLE " . MPREFIX . " online ADD online_active INT(10) UNSIGNED NOT NULL DEFAULT '0' " );
catch_error ( $sql );
}
if ( $sql -> db_Query ( " SHOW INDEX FROM " . MPREFIX . " tmp " ))
{
$row = $sql -> db_Fetch ();
if ( ! in_array ( 'tmp_ip' , $row ))
{
if ( $just_check ) return update_needed ();
$sql -> db_Select_gen ( " ALTER TABLE ` " . MPREFIX . " tmp` ADD INDEX `tmp_ip` (`tmp_ip`); " );
$sql -> db_Select_gen ( " ALTER TABLE ` " . MPREFIX . " upload` ADD INDEX `upload_active` (`upload_active`); " );
$sql -> db_Select_gen ( " ALTER TABLE ` " . MPREFIX . " generic` ADD INDEX `gen_type` (`gen_type`); " );
}
}
if ( ! $just_check )
{
// update new fields
require_once ( e_HANDLER . " plugin_class.php " );
$ep = new e107plugin ;
2012-12-23 15:00:15 +00:00
$ep -> update_plugins_table ( 'update' );
$ep -> save_addon_prefs ( 'update' );
2010-04-20 21:35:20 +00:00
}
if ( ! isset ( $pref [ 'displayname_maxlength' ]))
{
if ( $just_check ) return update_needed ();
$pref [ 'displayname_maxlength' ] = 15 ;
save_prefs ();
}
2013-02-11 14:25:59 +02:00
2010-04-20 21:35:20 +00:00
// If we get to here, in checking mode no updates are required. In update mode, all done.
if ( $just_check ) return TRUE ;
$admin_log -> log_event ( 'UPDATE_02' , LAN_UPDATE_14 . $e107info [ 'e107_version' ], E_LOG_INFORMATIVE , '' ); // Log result of actual update
return $just_check ; // TRUE if no updates needed, FALSE if updates needed and completed
}
2010-10-21 17:42:03 +00:00
/**
* Carries out the copy of timezone data from the user record to an extended user field
* @ return boolean TRUE on success , FALSE on failure
*/
2010-04-20 21:35:20 +00:00
function copy_user_timezone ()
{
2010-10-21 17:42:03 +00:00
$sql = e107 :: getDb ();
$sql2 = e107 :: getDb ( 'sql2' );
$tp = e107 :: getParser ();
require_once ( e_HANDLER . 'user_extended_class.php' );
$ue = new e107_user_extended ;
$tmp = $ue -> parse_extended_xml ( 'getfile' );
$tmp [ 'timezone' ][ 'parms' ] = $tp -> toDB ( $tmp [ 'timezone' ][ 'parms' ]);
if ( ! $ue -> user_extended_add ( $tmp [ 'timezone' ]))
{
return FALSE ;
}
2010-04-20 21:35:20 +00:00
2010-10-21 17:42:03 +00:00
// Created the field - now copy existing data
if ( $sql -> db_Select ( 'user' , 'user_id, user_timezone' ))
2010-04-20 21:35:20 +00:00
{
2010-10-21 17:42:03 +00:00
while ( $row = $sql -> db_Fetch ())
{
2013-03-09 15:09:33 -08:00
$sql2 -> update ( 'user_extended' , " `user_timezone`=' { $row [ 'user_timezone' ] } ' WHERE `user_extended_id`= { $row [ 'user_id' ] } " );
2010-10-21 17:42:03 +00:00
}
2010-04-20 21:35:20 +00:00
}
2010-10-21 17:42:03 +00:00
return TRUE ; // All done!
2010-04-20 21:35:20 +00:00
}
2010-10-21 17:42:03 +00:00
2010-04-20 21:35:20 +00:00
function update_needed ( $message = '' )
{
global $ns , $update_debug ;
$emessage = e107 :: getMessage ();
2013-03-27 19:34:45 -07:00
// if ($update_debug) $emessage->add("Update: ".$message, E_MESSAGE_DEBUG);
2010-04-20 21:35:20 +00:00
if ( E107_DEBUG_LEVEL )
{
$tmp = debug_backtrace ();
//$ns->tablerender("", "<div style='text-align:center'>Update required in ".basename(__FILE__)." on line ".$tmp[0]['line']."</div>");
$emessage -> add ( " Update required in " . basename ( __FILE__ ) . " on line " . $tmp [ 0 ][ 'line' ] . " ( " . $message . " ) " , E_MESSAGE_DEBUG );
}
return FALSE ;
}
/**
* Add index to a table . Returns FALSE if not required . Returns a message if required and just checking
*
* @ todo - get rid of $updateMessages parameter once log / message display method finalised , call the relevant method
*/
function addIndexToTable ( $target , $indexSpec , $just_check , & $updateMessages , $optionalTable = FALSE )
{
global $sql ;
if ( ! $sql -> db_Table_exists ( $target ))
{
if ( $optionalTable )
{
return ! $just_check ; // Nothing to do it table is optional and not there
}
$updateMessages [] = str_replace ( array ( '--TABLE--' , '--INDEX--' ), array ( $target , $indexSpec ), LAN_UPDATE_54 );
return ! $just_check ; // No point carrying on - return 'nothing to do'
}
if ( $sql -> db_Select_gen ( " SHOW INDEX FROM " . MPREFIX . $target ))
{
$found = FALSE ;
while ( $row = $sql -> db_Fetch ())
{ // One index per field
if ( in_array ( $indexSpec , $row ))
{
return ! $just_check ; // Found - nothing to do
}
}
// Index not found here
if ( $just_check )
{
return 'Required to add index to ' . $target ;
}
$sql -> db_Select_gen ( " ALTER TABLE ` " . MPREFIX . $target . " ` ADD INDEX ` " . $indexSpec . " ` (` " . $indexSpec . " `); " );
$updateMessages [] = str_replace ( array ( '--TABLE--' , '--INDEX--' ), array ( $target , $indexSpec ), LAN_UPDATE_37 );
}
return FALSE ;
}
/** Check for database access errors
* @ param reference $target - pointer to db object
* @ return none
*/
function catch_error ( & $target )
{
if ( vartrue ( $target -> getLastErrorText ()) && E107_DEBUG_LEVEL != 0 )
{
$tmp2 = debug_backtrace ();
$tmp = $target -> getLastErrorText ();
echo $tmp . " [ " . basename ( __FILE__ ) . " on line " . $tmp2 [ 0 ][ 'line' ] . " ] <br /> " ;
}
return ;
}
function get_default_prefs ()
{
2012-12-08 15:52:40 +01:00
$xmlArray = e107 :: getSingleton ( 'xmlClass' ) -> loadXMLfile ( e_CORE . " xml/default_install.xml " , 'advanced' );
2010-04-20 21:35:20 +00:00
$pref = e107 :: getSingleton ( 'xmlClass' ) -> e107ImportPrefs ( $xmlArray , 'core' );
return $pref ;
}
function convert_serialized ( $serializedData )
{
$arrayData = unserialize ( $serializedData );
2013-05-12 20:56:35 -07:00
return e107 :: serialize ( $arrayData , FALSE );
2010-04-20 21:35:20 +00:00
}
?>