assign( 'next_step', $step ); $schema = $gBitInstaller->mPackages; ksort( $schema ); $gBitSmarty->assign( 'schema', $schema ); // ===================== Post install table check ===================== // $dbTables is the output of BitSystem::verifyInstalledPackages() in // install_inc.php and contains all tables that are not present in the database // - even tables of packages that are not installed $dbIntegrity = install_check_database_integrity( $dbTables ); // ===================== Permissions ===================== // check all permissions, compare them to each other and see if there are old // permissions and ones that need to be inserted $query = "SELECT * FROM `".BIT_DB_PREFIX."users_permissions` ORDER BY `package` ASC"; $result = $gBitInstaller->mDb->query( $query ); while( !$result->EOF ) { foreach( $result->fields as $r ) { $bitPerms[$result->fields['perm_name']][] = $r; } $bitPerms[$result->fields['perm_name']]['sql'][] = "DELETE FROM `" . BIT_DB_PREFIX . "users_role_permissions` WHERE `perm_name`='" . $result->fields['perm_name'] . "'"; $bitPerms[$result->fields['perm_name']]['sql'][] = "DELETE FROM `" . BIT_DB_PREFIX . "users_permissions` WHERE `perm_name`='" . $result->fields['perm_name'] . "'"; $result->MoveNext(); } // we will make sure all the permission levels are what they should be. we will // update these without consulting the user. this is purely backend stuff, has // no outcome on the site itself but determines what the default permission // level is. the user can never modify these settings. foreach ( array_keys( $gBitInstaller->mPermHash ) as $perm ) { // permission level is stored in [2] $bindVars = []; if (!empty( $bitPerms[$perm] ) && $gBitInstaller->mPermHash[$perm][2] != $bitPerms[$perm][2]) { $query = "UPDATE `" . BIT_DB_PREFIX . "users_permissions` SET `perm_level` = ? WHERE `perm_name` = ?"; $bindVars[] = $gBitInstaller->mPermHash[$perm][2]; $bindVars[] = $perm; $gBitInstaller->mDb->query( $query, $bindVars ); } } // compare both perm arrays with each other and work out what permissions need // to be added and which ones removed $insPerms = $delPerms = []; foreach ( array_keys( $gBitInstaller->mPermHash ) as $perm ) { if (!in_array( $perm, array_keys( $bitPerms ) )) { if ($gBitInstaller->isInstalled( $gBitInstaller->mPermHash[$perm][3] )) { $insPerms[$perm] = $gBitInstaller->mPermHash[$perm]; } } } foreach ( array_keys( $bitPerms ) as $perm ) { if (!in_array( $perm, array_keys( $gBitInstaller->mPermHash ) )) { $delPerms[$perm] = $bitPerms[$perm]; } } $gBitSmarty->assign( 'delPerms', $delPerms ); $gBitSmarty->assign( 'insPerms', $insPerms ); // ===================== Services ===================== // check if we have installed more than one service of any given type // DEPRECATED - this check never really made sense. The original purpose // of the services was to have multiple under the same identifier to // be able to invoke them all in one shot. Recent updates to the services // flattens the array so that there is one and only one service set per // service type. This could revert back with time. For now this is commented // out. /* $serviceList = []; if( !empty( $gLibertySystem->mServices ) ) { foreach( $gLibertySystem->mServices as $service_name => $service ) { if( count( $service ) > 1 ) { $serviceList[$service_name] = $service; } } } */ // ===================== Process Form ===================== // create missing tables if possible if (!empty( $_REQUEST['create_tables'] ) && !empty( $dbIntegrity )) { $dict = NewDataDictionary( $gBitInstaller->mDb->mDb, 'firebird' ); if (!$gBitInstaller->mDb->getCaseSensitivity()) { $dict->connection->nameQuote = ''; } if (!empty( $gDebug ) || !empty( $_REQUEST['debug'] )) { $gBitInstaller->mDb->mDb->debug = 99; } // If we use MySql check which storage engine to use $build = isset( $_SESSION['use_innodb'] ) ? ( ( $_SESSION['use_innodb'] == true ) ? [ 'NEW', 'MYSQL' => 'ENGINE=INNODB' ] : [ 'NEW', 'MYSQL' => 'ENGINE=MYISAM' ] ) : 'NEW'; $tablePrefix = $gBitInstaller->getTablePrefix(); foreach( $dbIntegrity as $package => $info ) { foreach( $info['tables'] as $table ) { $completeTableName = $tablePrefix.$table['name']; $sql = $dict->CreateTableSQL( $completeTableName, $gBitInstaller->mPackages[$package]['tables'][$table['name']], $build ); if( $sql ) { $dict->ExecuteSQLArray( $sql ); } } } } // if any of the serviceList items have been unchecked, disable the appropriate packages if( !empty( $_REQUEST['resolve_conflicts'] ) ) { if( !empty( $gDebug ) || !empty( $_REQUEST['debug'] ) ) { $gBitInstallDb->debug = 99; } // === Permissions $fixedPermissions = []; $permMap = []; $permMap['basic'] = ANONYMOUS_TEAM_ID; $permMap['registered'] = 3; $permMap['editors'] = 2; $permMap['admin'] = 1; if( !empty( $_REQUEST['perms'] ) ) { foreach( $_REQUEST['perms'] as $perm ) { if( !empty( $delPerms[$perm] )) { foreach( $delPerms[$perm]['sql'] as $sql ) { $gBitInstaller->mDb->query( $sql ); } $fixedPermissions[] = $delPerms[$perm]; } if( !empty( $insPerms[$perm] )) { $gBitInstaller->mDb->query( $insPerms[$perm]['sql'] ); $fixedPermissions[] = $insPerms[$perm]; if( !empty( $roleMap[$insPerms[$perm][2]] )) { $gBitUser->assignPermissionToRole( $perm, $permMap[$insPerms[$perm][2]] ); } } } } $gBitSmarty->assign( 'fixedPermissions', $fixedPermissions ); // === Services $deActivated = []; foreach( $serviceList as $service ) { foreach( array_keys( $service ) as $package ) { $packages = !empty( $_REQUEST['packages'] ) ? $_REQUEST['packages'] : []; if( !in_array( $package, $packages )) { $gBitSystem->storeConfig( 'package_'.$package, 'n', KERNEL_PKG_NAME ); $deActivated[] = $package; } } } $gBitSmarty->assign( 'next_step', $step + 1 ); $gBitSmarty->assign( 'deActivated', $deActivated ); // display the confirmation page $app = '_done'; } elseif( !empty( $_REQUEST['skip'] ) ) { // if there were no conflicts, we move on to the next page header( "Location: ".$_SERVER['SCRIPT_NAME']."?step=".++$step ); die; } // make sure everything is up to date after the above changes $dbTables = $gBitInstaller->verifyInstalledPackages( 'all' ); $dbIntegrity = install_check_database_integrity( $dbTables ); $gBitSmarty->assign( 'dbIntegrity', $dbIntegrity ); // $gBitSmarty->assign( 'serviceList', $serviceList ); /** * function - install_check_database_integrity */ function install_check_database_integrity( $pDbTables ) { global $gBitInstaller; $ret = []; if( !empty( $pDbTables['missing'] ) && is_array( $pDbTables['missing'] )) { foreach( array_keys( $pDbTables['missing'] ) as $package ) { // we can't use the 'installed' flag in $gBitInstaller->mPackages[$package] because that is set to 'not installed' as soon as a table is missing if( count( $gBitInstaller->mPackages[$package]['tables'] ) > count( $pDbTables['missing'][$package] )) { // at least one table is missing $ret[$package] = [ 'name' => ucfirst( $gBitInstaller->mPackages[$package]['name'] ), 'required' => $gBitInstaller->mPackages[$package]['required'], ]; foreach( $pDbTables['missing'][$package] as $table ) { $ret[$package]['tables'][$table] = [ 'name' => $table, 'sql' => $gBitInstaller->mPackages[$package]['tables'][$table], ]; } } } } return $ret; }