mirror of
https://github.com/e107inc/e107.git
synced 2025-02-19 22:14:45 +01:00
Implemented upgrade_required() method as defined in forum_setup.php
Added some documentation on how to check for tables, fields and indexes and how to remove fields and indexes
This commit is contained in:
parent
eeaa9b22a8
commit
a7f1271eb4
@ -78,6 +78,96 @@ if(!class_exists("_blank_setup"))
|
|||||||
// print_a($var);
|
// print_a($var);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Call During Upgrade Check. May be used to check for existance of tables etc and if not found return TRUE to call for an upgrade.
|
||||||
|
*
|
||||||
|
* @return bool true = upgrade required; false = upgrade not required
|
||||||
|
*/
|
||||||
|
function upgrade_required()
|
||||||
|
{
|
||||||
|
// Check if a specific table exists and if not, return true to force a db update
|
||||||
|
// In this example, it checks if the table "blank_table" exists
|
||||||
|
// if(!e107::getDb()->isTable('blank_table'))
|
||||||
|
// {
|
||||||
|
// return true; // true to trigger an upgrade alert, and false to not.
|
||||||
|
// }
|
||||||
|
|
||||||
|
|
||||||
|
// Check if a specific field exists in the specified table
|
||||||
|
// and if not return false to force a db update to add this field
|
||||||
|
// from the "_blank_sql.php" file
|
||||||
|
// In this case: Exists field "blank_id" in table "blank_table"
|
||||||
|
// if(!e107::getDb()->field('blank_table','blank_id'))
|
||||||
|
// {
|
||||||
|
// return true; // true to trigger an upgrade alert, and false to not.
|
||||||
|
// }
|
||||||
|
|
||||||
|
|
||||||
|
// In case you need to delete a field that is not used anymore,
|
||||||
|
// first check if the field exists, than run a sql command to drop (delete) the field
|
||||||
|
// !!! ATTENTION !!!
|
||||||
|
// !!! Deleting a field, deletes also the data stored in that field !!!
|
||||||
|
// !!! Make sure you know what you are doing !!!
|
||||||
|
//
|
||||||
|
// In this example, the field "blank_unused_field" from table "blank_table"
|
||||||
|
// isn't used anymore and will be deleted (dropped) if it still exists
|
||||||
|
// if(e107::getDb()->field('blank_table', 'blank_unused_field'))
|
||||||
|
// {
|
||||||
|
// this statement directly deletes the field, an additional
|
||||||
|
// db update isn't needed anymore, if this is the only change on the db/table.
|
||||||
|
// e107::getDb()->gen("ALTER TABLE `#blank_table` DROP `blank_unused_field` ");
|
||||||
|
// }
|
||||||
|
|
||||||
|
|
||||||
|
// In case you need to delete a index that is not used anymore,
|
||||||
|
// first check if the index exists, than run a sql command to drop (delete) the field
|
||||||
|
// Be aware, that deleting an index is not very harmfull, as the data of the
|
||||||
|
// index will be recreated when the index is added again.
|
||||||
|
// if(e107::getDb()->index('blank_table','blank_unused_index'))
|
||||||
|
// {
|
||||||
|
// this statement directly deletes the index, an additional
|
||||||
|
// db update isn't needed anymore, if this is the only change on the db/table.
|
||||||
|
// e107::getDb()->gen("ALTER TABLE `#blank_table` DROP INDEX `blank_unused_index` ");
|
||||||
|
// }
|
||||||
|
|
||||||
|
// In case you need to check an index and which fields it is build of,
|
||||||
|
// use the fourth parameter to return the index definition.
|
||||||
|
// In this case, the index should be deleted if consists only of 1 field ("blank_fieldname"),
|
||||||
|
// if(e107::getDb()->index('blank_table','blank_unused_index', array('blank_fieldname')))
|
||||||
|
// {
|
||||||
|
// this statement directly deletes the index, an additional
|
||||||
|
// db update isn't needed anymore, if this is the only change on the db/table.
|
||||||
|
// e107::getDb()->gen("ALTER TABLE `#blank_table` DROP INDEX `blank_unused_index` ");
|
||||||
|
// }
|
||||||
|
|
||||||
|
|
||||||
|
// In case you need to check an index and which fields it is build of,
|
||||||
|
// use the third parameter to return the index definition.
|
||||||
|
// In this case, the index should be deleted if consists only of 1 field ("blank_fieldname"),
|
||||||
|
// if ($index_def = e107::getDb()->index('blank_table','blank_unused_index', array('blank_fieldname')))
|
||||||
|
// {
|
||||||
|
// Check if the key should be UNIQUE
|
||||||
|
// $unique = array_count_values(array_column($index_def, 'Non_unique'));
|
||||||
|
// if($unique[1] > 0) // Keys are not unique
|
||||||
|
// {
|
||||||
|
// this statement directly deletes the index, an additional
|
||||||
|
// db update isn't needed anymore, if this is the only change on the db/table.
|
||||||
|
// e107::getDb()->gen("ALTER TABLE `#blank_table` DROP INDEX `blank_unused_index` ");
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
|
||||||
|
$legacyMenuPref = e107::getConfig('menu')->getPref();
|
||||||
|
if(isset($legacyMenuPref['newforumposts_caption']))
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
function upgrade_post($var)
|
function upgrade_post($var)
|
||||||
{
|
{
|
||||||
// $sql = e107::getDb();
|
// $sql = e107::getDb();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user