summaryrefslogtreecommitdiff
path: root/install_packages.php
diff options
context:
space:
mode:
authorMax Kremmel <xing@synapse.plus.com>2007-01-06 18:06:35 +0000
committerMax Kremmel <xing@synapse.plus.com>2007-01-06 18:06:35 +0000
commit54e4aafc0f8f61aab7b61c255806976f3796c4f9 (patch)
tree2a6b8ce8d089b8b3865c4a4510298cecf64aaed9 /install_packages.php
parentee96e9bfe1cf78061e7918e16be2a550105f7bb1 (diff)
downloadinstall-54e4aafc0f8f61aab7b61c255806976f3796c4f9.tar.gz
install-54e4aafc0f8f61aab7b61c255806976f3796c4f9.tar.bz2
install-54e4aafc0f8f61aab7b61c255806976f3796c4f9.zip
first stab at a flexible content uninstaller. some stuff probably needs some more testing and we also need to think about how to physically remove files from the harddisk when uninstalling stuff like fisheye or treasury. ideally we should have a confirmation page that lists all the content that's about to be nuked, but i just can't be asked...
Diffstat (limited to 'install_packages.php')
-rw-r--r--install_packages.php184
1 files changed, 142 insertions, 42 deletions
diff --git a/install_packages.php b/install_packages.php
index 3b968ac..d7916d1 100644
--- a/install_packages.php
+++ b/install_packages.php
@@ -1,6 +1,6 @@
<?php
/**
- * @version $Header: /cvsroot/bitweaver/_bit_install/install_packages.php,v 1.46 2006/12/29 05:17:50 spiderr Exp $
+ * @version $Header: /cvsroot/bitweaver/_bit_install/install_packages.php,v 1.47 2007/01/06 18:06:35 squareing Exp $
* @package install
* @subpackage functions
*/
@@ -35,6 +35,9 @@ if( !empty( $_REQUEST['packages'] ) && in_array( 'users', $_REQUEST['packages']
if( !empty( $_REQUEST['cancel'] ) ) {
header( 'Location: '.INSTALL_PKG_URL.'install.php?step='.( $step + 1 ) );
} elseif( !empty( $_REQUEST['packages'] ) && is_array( $_REQUEST['packages'] ) && !empty( $_REQUEST['method'] ) && !empty( $_REQUEST['submit_packages'] ) ) {
+ // shorthand for the actions we are supposed to perform during an unistall or re-install
+ $removeActions = !empty( $_REQUEST['remove_actions'] ) ? $_REQUEST['remove_actions'] : array();
+
// make sure that required pkgs are only present when we are installing
if( ( $method = ( $_REQUEST['method'] ) ) == 'install' && !$_SESSION['first_install'] ) {
foreach( array_keys( $gBitInstaller->mPackages ) as $package ) {
@@ -43,6 +46,10 @@ if( !empty( $_REQUEST['cancel'] ) ) {
$method = FALSE;
}
}
+ } elseif( empty( $removeActions ) ) {
+ // we are un / reinstalling stuff but no actions have been selected
+ $gBitSmarty->assign( 'warning', "You have selected to un / reinstall packages but have not selected any options. Please select at least one." );
+ return FALSE;
}
if( $gBitDbType == 'sybase' ) {
@@ -82,22 +89,26 @@ if( !empty( $_REQUEST['cancel'] ) ) {
// value into other packages tables - typically users_permissions, bit_preferences, etc...
sort( $_REQUEST['packages'] );
- // 1. let's generate all the tables's
+
+
+ // ---------------------- 1. ----------------------
+ // let's generate all the tables's
foreach( array_keys( $gBitInstaller->mPackages ) as $package ) {
- if( in_array( $package, $_REQUEST['packages'] ) ) {
+ if( in_array( $package, $_REQUEST['packages'] )) {
// work out what we're going to do with this package
if ( $method == 'install' && $_SESSION['first_install'] ) {
$build = array( 'NEW' );
- } elseif( $method == "install" && empty( $gBitInstaller->mPackages[$package]['installed'] ) ) {
+ } elseif( $method == "install" && empty( $gBitInstaller->mPackages[$package]['installed'] )) {
$build = array( 'NEW' );
- } elseif( $method == "reinstall" && !empty( $gBitInstaller->mPackages[$package]['installed'] ) ) {
+ } elseif( $method == "reinstall" && !empty( $gBitInstaller->mPackages[$package]['installed'] ) && in_array( 'tables', $removeActions )) {
+ // only set $build if we want to reset the tables - this allows us to reset a package to it's starting values without deleting any content
$build = array( 'REPLACE' );
- } elseif( $method == "uninstall" && $gBitInstaller->mPackages[$package]['installed'] == 1 ) {
+ } elseif( $method == "uninstall" && !empty( $gBitInstaller->mPackages[$package]['installed'] ) && in_array( 'tables', $removeActions )) {
$build = array( 'DROP' );
}
- // Install tables
- if( !empty( $gBitInstaller->mPackages[$package]['tables'] ) && is_array( $gBitInstaller->mPackages[$package]['tables'] ) ) {
+ // Install tables - $build is empty when we don't pick tables when un / reinstalling packages
+ if( !empty( $gBitInstaller->mPackages[$package]['tables'] ) && is_array( $gBitInstaller->mPackages[$package]['tables'] ) && !empty( $build )) {
foreach( array_keys( $gBitInstaller->mPackages[$package]['tables'] ) as $tableName ) {
$completeTableName = $tablePrefix.$tableName;
$sql = $dict->CreateTableSQL( $completeTableName, $gBitInstaller->mPackages[$package]['tables'][$tableName], $build );
@@ -113,32 +124,37 @@ if( !empty( $_REQUEST['cancel'] ) ) {
}
}
- // 2. let's generate all the indexes, and sequences
+
+
+ // ---------------------- 2. ----------------------
+ // let's generate all the indexes, and sequences
foreach( array_keys( $gBitInstaller->mPackages ) as $package ) {
if( in_array( $package, $_REQUEST['packages'] ) ) {
- if( $method == 'install' || $method == 'reinstall' ) {
- $schemaQuote = strrpos( BIT_DB_PREFIX, '`' );
- $sequencePrefix = ( $schemaQuote ? substr( BIT_DB_PREFIX, $schemaQuote + 1 ) : BIT_DB_PREFIX );
+ // set prefix
+ $schemaQuote = strrpos( BIT_DB_PREFIX, '`' );
+ $sequencePrefix = ( $schemaQuote ? substr( BIT_DB_PREFIX, $schemaQuote + 1 ) : BIT_DB_PREFIX );
+ if( $method == 'install' || ( $method == 'reinstall' && in_array( 'tables', $removeActions ))) {
// Install Indexes
if( isset( $gBitInstaller->mPackages[$package]['indexes'] ) && is_array( $gBitInstaller->mPackages[$package]['indexes'] ) ) {
foreach( array_keys( $gBitInstaller->mPackages[$package]['indexes'] ) as $tableIdx ) {
$completeTableName = $sequencePrefix.$gBitInstaller->mPackages[$package]['indexes'][$tableIdx]['table'];
$sql = $dict->CreateIndexSQL( $tableIdx, $completeTableName, $gBitInstaller->mPackages[$package]['indexes'][$tableIdx]['cols'], $gBitInstaller->mPackages[$package]['indexes'][$tableIdx]['opts'] );
- if( $sql && ($dict->ExecuteSQLArray( $sql ) > 0 ) ) {
+ if( $sql && ( $dict->ExecuteSQLArray( $sql ) > 0 ) ) {
} else {
print '<span class="error">Failed to create '.$completeTableName.'</span>';
array_push( $failedcommands, $sql );
}
}
}
+
if( isset( $gBitInstaller->mPackages[$package]['sequences'] ) && is_array( $gBitInstaller->mPackages[$package]['sequences'] ) ) {
foreach( array_keys( $gBitInstaller->mPackages[$package]['sequences'] ) as $sequenceIdx ) {
$sql = $gBitInstallDb->CreateSequence( $sequencePrefix.$sequenceIdx, $gBitInstaller->mPackages[$package]['sequences'][$sequenceIdx]['start'] );
}
}
- } elseif( $method == 'uninstall' ) {
+ } elseif( $method == 'uninstall' && in_array( 'tables', $removeActions )) {
if( isset( $gBitInstaller->mPackages[$package]['sequences'] ) && is_array( $gBitInstaller->mPackages[$package]['sequences'] ) ) {
foreach( array_keys( $gBitInstaller->mPackages[$package]['sequences'] ) as $sequenceIdx ) {
$sql = $gBitInstallDb->DropSequence( $sequencePrefix.$sequenceIdx );
@@ -151,57 +167,138 @@ if( !empty( $_REQUEST['cancel'] ) ) {
$gBitInstaller->mPrefs = '';
$gBitInstaller->loadConfig();
- // 3. activate all selected & required packages
+
+
+ // ---------------------- 3. ----------------------
+ // manipulate the data in kernel_config
foreach( array_keys( $gBitInstaller->mPackages ) as $package ) {
if( in_array( $package, $_REQUEST['packages'] ) ) {
+ // remove all the requested settings - this is a bit tricky and might require some more testing
+ // Remove settings if requested
+ if( in_array( 'settings', $removeActions ) ) {
+ // get a list of permissions used by this package
+ $query = "SELECT `perm_name` FROM `".$tablePrefix."users_permissions` WHERE `package`=?";
+ $perms = $gBitInstaller->mDb->getCol( $query, array( $package ));
+ // we deal with users_object_permissions below
+ $tables = array( 'users_group_permissions', 'users_permissions' );
+ foreach( $tables as $table ) {
+ foreach( $perms as $perm ) {
+ $delete = "
+ DELETE FROM `".$tablePrefix.$table."`
+ WHERE `perm_name`=?";
+ $gBitInstaller->mDb->query( $delete, array( $perm ) );
+ }
+ }
+
+ // list of tables where we store package specific settings
+ $tables = array( 'kernel_config' );
+ foreach( $tables as $table ) {
+ $delete = "
+ DELETE FROM `".$tablePrefix.$table."`
+ WHERE `package`=?";
+ $gBitInstaller->mDb->query( $delete, array( $package ) );
+ }
+ }
+
+ // now we can start removing content if requested
+ // lots of foreach loops in here
+ if( in_array( 'content', $removeActions ) ) {
+ // first we need to work out the package specific content details
+ foreach( $gLibertySystem->mContentTypes as $contentType ) {
+ if( $contentType['handler_package'] == $package ) {
+ // first we get a list of content_ids which we can use to scan various tables without content_type_guid column for data
+ $query = "SELECT `content_id` FROM `".$tablePrefix."liberty_content` WHERE `content_type_guid`=?";
+ $rmContentIds = $gBitInstaller->mDb->getCol( $query, array( $contentType['content_type_guid'] ));
+
+ // list of core tables where bitweaver might store relevant data
+ // firstly, we delete using the content ids
+ // order is important due to the constraints set in the schema
+ $tables = array(
+ 'liberty_aliases' => 'content_id',
+ 'liberty_structures' => 'content_id',
+ 'liberty_content_hits' => 'content_id',
+ 'liberty_content_history' => 'content_id',
+ 'liberty_content_prefs' => 'content_id',
+ 'liberty_content_links' => 'to_content_id',
+ 'liberty_content_links' => 'from_content_id',
+ 'users_favorites_map' => 'favorite_content_id'
+ // not sure about liberty_attachments. will they get lost?
+ //'liberty_attachments' => 'content_id',
+ // don't think we should remove comments, since these might be in use by boards
+ //'liberty_comments' => 'content_id',
+ );
+ foreach( $rmContentIds as $contentId ) {
+ foreach( $tables as $table => $column ) {
+ $delete = "
+ DELETE FROM `".$tablePrefix.$table."`
+ WHERE `$column`=?";
+ $gBitInstaller->mDb->query( $delete, array( $contentId ));
+ }
+
+ // special case: users_object_permissions
+ $delete = "
+ DELETE FROM `".$tablePrefix."users_object_permissions`
+ WHERE `object_id`=? AND `object_type`=?";
+ $gBitInstaller->mDb->query( $delete, array( $contentId, $contentType['content_type_guid'] ));
+ }
+
+ // TODO: we need to physically remove files from the server when we uninstall stuff like fisheye and treasury
+ // i think we'll need to call the appropriate expunge function but i'm too tired to work out how or where to get that info from
+
+ // secondly, we delete using the content type guid
+ // order is important due to the constraints set in the schema
+ $tables = array( 'liberty_content', 'liberty_content_types' );
+ foreach( $tables as $table ) {
+ $delete = "
+ DELETE FROM `".$tablePrefix.$table."`
+ WHERE `content_type_guid`=?";
+ $gBitInstaller->mDb->query( $delete, array( $contentType['content_type_guid'] ));
+ }
+ }
+ }
+ }
+
+ // set active packages
if( $method == 'install' || $method == 'reinstall' ) {
$gBitSystem->storeConfig( 'package_'. $package , 'y', $package );
$gBitInstaller->mPackages[ $package ]['installed'] = TRUE;
$gBitInstaller->mPackages[ $package ]['active_switch'] = TRUE;
// we'll default wiki to the home page
- if( defined( 'WIKI_PKG_NAME' ) && $package == WIKI_PKG_NAME ) {
+ if( defined( 'WIKI_PKG_NAME' ) && $package == WIKI_PKG_NAME && !$gBitSystem->isFeatureActive( 'bit_index' )) {
$gBitSystem->storeConfig( "bit_index", WIKI_PKG_NAME, WIKI_PKG_NAME );
}
- } elseif( $method == 'uninstall' ) {
- // TODO: allow option to remove related content from liberty_content and liberty_structures
- // should be possible using $gLibertySystem->mContentTypes and the appropriate GUIDs
- // Cascade user_preferences if necessary
-// this has to be done using the individual content_ids from liberty_content
-// $delete = "DELETE FROM `".$tablePrefix."liberty_content_prefs` " .
-// "WHERE `pref_name` IN ( SELECT `name` FROM `kernel_prefs` WHERE `package` = '".$package."')";
-// $gBitInstaller->mDb->query( $delete );
- // Delete user_permissions ( need to ensure package is set in table )
- $delete = "DELETE FROM `".$tablePrefix."users_permissions`
- WHERE `package` = '".$package."'";
- $gBitInstaller->mDb->query( $delete );
- // Delete preferences ( need to ensure package is set in table )
- $delete = "DELETE FROM `".$tablePrefix."kernel_config`
- WHERE `package` = '".$package."'";
- $gBitInstaller->mDb->query( $delete );
}
}
}
+ // Tonnes of stuff has changed. Force a reload of all our preferences
+ $gBitInstaller->mPrefs = '';
+ $gBitInstaller->loadConfig();
+
+
# this is bad if phpBB isn't being used...
# // and let's turn on phpBB so people can find it easily.
# if( defined( 'PHPBB_PKG_NAME' ) ) {
# $gBitSystem->storeConfig( 'package_phpbb', 'y', PHPBB_PKG_NAME );
# }
- // 4. run the defaults through afterwards so we can be sure all tables needed have been created
+
+
+ // ---------------------- 4. ----------------------
+ // run the defaults through afterwards so we can be sure all tables needed have been created
foreach( array_keys( $gBitInstaller->mPackages ) as $package ) {
- if (!empty($package)) {
+ if( !empty( $package )) {
if( in_array( $package, $_REQUEST['packages'] ) || ( empty( $gBitInstaller->mPackages[$package]['installed'] ) && !empty( $gBitInstaller->mPackages[$package]['required'] ) ) ) {
- if( $method == 'install' || $method == 'reinstall' ) {
+ if( $method == 'install' || ( $method == 'reinstall' && in_array( 'settings', $removeActions ))) {
// this list of installed packages is used to show newly installed packages
if( !empty( $gBitInstaller->mPackages[$package]['defaults'] ) ) {
foreach( $gBitInstaller->mPackages[$package]['defaults'] as $def ) {
- if ($gBitInstaller->mDb->mType == 'firebird' ) $def = preg_replace("/\\\'/","''", $def );
+ if( $gBitInstaller->mDb->mType == 'firebird' ) {
+ $def = preg_replace( "/\\\'/", "''", $def );
+ }
$gBitInstaller->mDb->query( $def );
}
}
- } else {
- // This is where any links to clear data not in the current package will be processed
}
// this is to list any processed packages
$packageList[$method][] = $package;
@@ -209,11 +306,10 @@ if( !empty( $_REQUEST['cancel'] ) ) {
}
}
- // Do first install stuff only
+ // ---------------------- 5. ----------------------
+ // Do stuff that only applies during the first install
if( isset( $_SESSION['first_install'] ) && $_SESSION['first_install'] == TRUE ) {
- /**
- * Some packages have some special things to take care of here.
- */
+ // Some packages have some special things to take care of here.
foreach( $gBitInstaller->mInstallModules as $mod ) {
$mod['user_id'] = ROOT_USER_ID;
if( !isset( $mod['layout'] ) ) {
@@ -285,6 +381,10 @@ if( !empty( $_REQUEST['cancel'] ) ) {
}
}
+
+
+ // ---------------------- 6. ----------------------
+ // woo! we're done with the installation bit - below here is some generic installer stuff
$gBitSmarty->assign( 'next_step', $step + 1 );
// display list of installed packages