install
[ class tree: install ] [ index: install ] [ all elements ]

Source for file install_packages.php

Documentation is available at install_packages.php

  1. <?php
  2. /**
  3.  * @version $Header$
  4.  * @package install
  5.  * @subpackage functions
  6.  *
  7.  * @copyright (c) 2002-2003, Luis Argerich, Garland Foster, Eduardo Polidor, et. al.
  8.  *  All Rights Reserved. See below for details and a complete list of authors.
  9.  *  Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See http://www.gnu.org/copyleft/lesser.html for details.
  10.  */
  11.  
  12. /**
  13.  * we set this variable since || admin >> kernel >> packages || uses this file as well
  14.  */
  15. if!isset$step ) ) {
  16.     $step NULL;
  17. }
  18.  
  19. // set the maximum execution time to very high
  20. ini_set"max_execution_time""86400" );
  21.  
  22. // assign next step in installation process
  23. $gBitSmarty->assign'next_step'$step );
  24.  
  25. // pass all package data to template
  26. $schema $gBitInstaller->mPackages;
  27. ksort$schema );
  28. $gBitSmarty->assign_by_ref'schema'$schema );
  29.  
  30. // confirm that we have all the admin data in the session before proceeding
  31. if!empty$_REQUEST['packages'&& in_array'users'$_REQUEST['packages'&& empty$_SESSION['login'|| empty$_SESSION['password'|| empty$_SESSION['email') ) ) {
  32.     // we have lost our session password and we are not installed
  33.     header'Location: '.INSTALL_PKG_URL.'install.php?step=1' );
  34.     die;
  35. }
  36.  
  37. if!empty$_REQUEST['cancel') ) {
  38.     header'Location: '.INSTALL_PKG_URL.'install.php?step='.$step ) );
  39. elseif!empty$_REQUEST['packages'&& is_array$_REQUEST['packages'&& !empty$_REQUEST['method'&& !empty$_REQUEST['submit_packages') ) {
  40.     // shorthand for the actions we are supposed to perform during an unistall or re-install
  41.     $removeActions !empty$_REQUEST['remove_actions'$_REQUEST['remove_actions'array();
  42.  
  43.     // Override reinstall/uninstall flag
  44.     if $_REQUEST['submit_packages'== 'Install Packages' $_REQUEST['method''install';
  45.     // make sure that required pkgs are only present when we are installing
  46.     if(( $method $_REQUEST['method')) == 'install' && !$_SESSION['first_install'{
  47.         // make sure no required packages are included in this list
  48.         foreacharray_keys$gBitInstaller->mPackages as $package {
  49.             ifin_array$package$_REQUEST['packages'&& !empty$gBitInstaller->mPackages[$package]['required')) {
  50.                 $gBitSmarty->assign'warning'"Something unexpected has happened: One of the required packages has appeared in the list of selected packages. This generally only happens if the installation is missing a core database table. Please contact the bitweaver developers team on how to proceed." );
  51.                 $method FALSE;
  52.             }
  53.         }
  54.     elseif$method != 'install' && empty$removeActions ) ) {
  55.         // we are un / reinstalling stuff but no actions have been selected
  56.         $gBitSmarty->assign'warning'"You have selected to un / reinstall packages but have not selected any options. Please select at least one." );
  57.         return FALSE;
  58.     }
  59.  
  60.     if$gBitDbType == 'sybase' {
  61.         // avoid database change messages
  62.         ini_set('sybct.min_server_severity''11');
  63.     }
  64.  
  65.     $gBitInstallDb ADONewConnection$gBitDbType );
  66.  
  67.     if!empty$gDebug || !empty$_REQUEST['debug') ) {
  68.         $gBitInstaller->mDb->debug(99);
  69.         $gBitInstallDb->debug 99;
  70.     }
  71.  
  72.     // by now $method should be populated with something
  73.     if$gBitInstallDb->Connect$gBitDbHost$gBitDbUser$gBitDbPassword$gBitDbName && !empty$method ) ) {
  74.         if $_SESSION['first_install'&& $gBitDbType == 'firebird' {
  75. // Leave commented for present, new installations on Firebird should use FB2.1.x and above which have an internal function library
  76. //            $result = $gBitInstallDb->Execute( "DECLARE EXTERNAL FUNCTION LOWER CSTRING(80) RETURNS CSTRING(80) FREE_IT ENTRY_POINT 'IB_UDF_lower' MODULE_NAME 'ib_udf'" );
  77. //            $result = $gBitInstallDb->Execute( "DECLARE EXTERNAL FUNCTION RAND RETURNS DOUBLE PRECISION BY VALUE ENTRY_POINT 'IB_UDF_rand' MODULE_NAME 'ib_udf'" );
  78.         }
  79.  
  80.         $tablePrefix $gBitInstaller->getTablePrefix();
  81.  
  82.         $dict NewDataDictionary$gBitInstallDb );
  83.  
  84.         if!$gBitInstaller->mDb->getCaseSensitivity() ) {
  85.             // set nameQuote to blank
  86.             $dict->connection->nameQuote '';
  87.         }
  88.  
  89.         // When using MySql and installing further packages after first install
  90.         // check to see what storage engine in use, InnoDb or MyIsam,
  91.         // so we don't end up with mixed table types.
  92.         if$gBitInstaller->isInstalled() ) {
  93.             global $gBitDbType;
  94.             ifpreg_match'/mysql/'$gBitDbType )) {
  95.                 $_SESSION['use_innodb'FALSE;
  96.                 $rs $gBitDb->Execute("SHOW TABLE STATUS LIKE '%kernel_config'");
  97.                 while !$rs->EOF{
  98.                     $row $rs->GetRowAssoc(false);
  99.                     switchisset$row['Engine'strtoupper$row['Engine'strtoupper$row['Type')) {
  100.                         case 'INNODB':
  101.                         case 'INNOBASE':
  102.                             $_SESSION['use_innodb'TRUE;
  103.                             break 2;
  104.                     }
  105.  
  106.                     $rs->MoveNext();
  107.                 }
  108.                 $rs->Close();
  109.             }
  110.         }
  111.  
  112.         $sqlArray array();
  113.  
  114.         //error_reporting( E_ALL );
  115.         // packages are sorted alphabetically. but we really need a /etc/rc.d/rc.3 style loading precidence!
  116.         // We perform several loops through mPackages due to foreign keys, and some packages may insert
  117.         // value into other packages tables - typically users_permissions, bit_preferences, etc...
  118.         sort$_REQUEST['packages');
  119.  
  120.         // Need to unquote constraints. but this need replacing with a datadict function
  121.         require_once('../kernel/BitDbBase.php');
  122.         $gBitKernelDb new BitDb();
  123.         $gBitKernelDb->mType $gBitDbType;
  124.  
  125.         // ---------------------- 1. ----------------------
  126.         // let's generate all the tables's
  127.         $gBitInstallDb->StartTrans();
  128.         $uninstalledPackages array();
  129.         // get a list of packages to install maintained gScanOrder from mPackages
  130.         foreacharray_keys$gBitInstaller->mPackages as $p {
  131.             ifin_array$p$_REQUEST['packages') ) {
  132.                 $uninstalledPackages[$p;
  133.             }
  134.         }
  135.  
  136.         $maxLoop count$uninstalledPackages count$uninstalledPackages );
  137.  
  138.         $i 0;
  139.         $installedPackages array();
  140.         foreacharray_keys$gBitInstaller->mPackages as $key {
  141.             if!empty$gBitInstaller->mPackages[$package]['installed') ) {
  142.                 array_push$installedPackages$package );
  143.             }
  144.         }
  145.  
  146.         do {
  147.             $package array_shift$uninstalledPackages );
  148.             $dependentPackages (!empty$gBitInstaller->mPackages[$package]['info']['dependencies'explode','$gBitInstaller->mPackages[$package]['info']['dependencies'array());
  149.             $dependentsInstalled array_intersect$dependentPackages$installedPackages );
  150.             $dependentsUninstalled array_intersect$dependentPackages$uninstalledPackages );
  151.             if!empty$dependentPackages && (count$dependentsUninstalled count$dependentsInstalled )) != count$dependentPackages ) ) {
  152.                 // total dependents is not the same as what is/will be installed
  153.                 $errors['Required package is missing: '.$package.' requires '.$gBitInstaller->mPackages['info']['dependencies'];
  154.             elseifempty$gBitInstaller->mPackages[$package]['requirements'&& count$dependentsInstalled == count$dependentPackages ) ) {
  155.                 unset$build );
  156.                 // work out what we're going to do with this package
  157.                 if $method == 'install' && $_SESSION['first_install'{
  158.                     $build array'NEW' );
  159.                 elseif$method == "install" && empty$gBitInstaller->mPackages[$package]['installed')) {
  160.                     $build array'NEW' );
  161.                 elseif$method == "reinstall" && !empty$gBitInstaller->mPackages[$package]['installed'&& in_array'tables'$removeActions )) {
  162.                     // 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
  163.                     $build array'REPLACE' );
  164.                 elseif$method == "uninstall" && !empty$gBitInstaller->mPackages[$package]['installed'&& in_array'tables'$removeActions )) {
  165.                     $build array'DROP' );
  166.                 }
  167.                 // If we use MySql and not DROP anything
  168.                 // set correct storage engine to use
  169.                 ifisset$_SESSION['use_innodb'&& isset$build &&  $build['0'!= 'DROP' ){
  170.                     if$_SESSION['use_innodb'== TRUE{
  171.                         $build array_merge($buildarray('MYSQL' => 'ENGINE=INNODB'));
  172.                     else {
  173.                         $build array_merge($buildarray('MYSQL' => 'ENGINE=MYISAM'));
  174.                     }
  175.                 }
  176.                 // Install tables - $build is empty when we don't pick tables, when un / reinstalling packages
  177.                 if!empty$gBitInstaller->mPackages[$package]['tables'&& is_array$gBitInstaller->mPackages[$package]['tables'&& !empty$build )) {
  178.                     foreacharray_keys$gBitInstaller->mPackages[$package]['tables'as $tableName {
  179.                         $completeTableName $tablePrefix.$tableName;
  180.                         // in case prefix has backticks for schema
  181.                         $sql $dict->CreateTableSQL$completeTableName$gBitInstaller->mPackages[$package]['tables'][$tableName]$build );
  182.                         // Uncomment this line to see the create sql
  183.                         for$sqlIdx 0$sqlIdx count$sql )$sqlIdx++ {
  184.                             $gBitKernelDb->convertQuery$sql[$sqlIdx);
  185.                         }
  186.                         if$sql && $dict->ExecuteSQLArray$sql <= 1{
  187.                             $errors['Failed to create table '.$completeTableName;
  188.                             $failedcommands[implode(" "$sql);
  189.                         }
  190.                     }
  191.                 }
  192.                 $installedPackages[$package;
  193.             else {
  194.                 // push dependent package on the end of uninstalled array
  195.                 array_push$uninstalledPackages$package );
  196.             }
  197.  
  198.             $i++;
  199.         while!empty$uninstalledPackages && $i $maxLoop );
  200.  
  201.         if$i $maxLoop {
  202.             $errors['Infinite loop detected';
  203.         }
  204.  
  205.  
  206.         // ---------------------- 2. ----------------------
  207.         // install additional constraints
  208.         foreacharray_keys$gBitInstaller->mPackages as $package {
  209.             ifin_array$package$_REQUEST['packages'&& ($method == 'install' || $method == 'reinstall' )
  210.                 && !empty$gBitInstaller->mPackages[$package]['constraints'&& is_array$gBitInstaller->mPackages[$package]['constraints') ) {
  211.                 foreacharray_keys($gBitInstaller->mPackages[$package]['constraints']as $tableName {
  212.                     $completeTableName $tablePrefix.$tableName;
  213.                     foreacharray_keys($gBitInstaller->mPackages[$package]['constraints'][$tableName]as $constraintName {
  214.                         $sql 'ALTER TABLE `'.$completeTableName.'` ADD CONSTRAINT `'.$constraintName.'` '.$gBitInstaller->mPackages[$package]['constraints'][$tableName][$constraintName];
  215.                         $gBitKernelDb->convertQuery($sql);
  216.                         $ret $gBitInstallDb->Execute$sql );
  217.                         if $ret === false {
  218.                             $errors['Failed to add constraint '.$constraintName.' to table '.$completeTableName;
  219.                             $failedcommands[$sql;
  220.                         }
  221.                     }
  222.                 }
  223.             }
  224.         }
  225.  
  226.  
  227.  
  228.         // ---------------------- 3. ----------------------
  229.         // let's generate all the indexes, and sequences
  230.         foreacharray_keys$gBitInstaller->mPackages as $package {
  231.             ifin_array$package$_REQUEST['packages') ) {
  232.                 // set prefix
  233.                 $schemaQuote strrposBIT_DB_PREFIX'`' );
  234.                 $sequencePrefix $schemaQuote substrBIT_DB_PREFIX,  $schemaQuote BIT_DB_PREFIX );
  235.  
  236.                 if$method == 'install' || $method == 'reinstall' && in_array'tables'$removeActions ))) {
  237.                     // Install Indexes
  238.                     ifisset$gBitInstaller->mPackages[$package]['indexes'&& is_array$gBitInstaller->mPackages[$package]['indexes') ) {
  239.                         foreacharray_keys$gBitInstaller->mPackages[$package]['indexes'as $tableIdx {
  240.                             $completeTableName $sequencePrefix.$gBitInstaller->mPackages[$package]['indexes'][$tableIdx]['table'];
  241.  
  242.                             $sql $dict->CreateIndexSQL$tableIdx$completeTableName$gBitInstaller->mPackages[$package]['indexes'][$tableIdx]['cols']$gBitInstaller->mPackages[$package]['indexes'][$tableIdx]['opts');
  243.                             if$sql && $dict->ExecuteSQLArray$sql <= 1{
  244.                                 $errors['Failed to create index '.$tableIdx." on ".$completeTableName;
  245.                                 $failedcommands[implode(" "$sql);
  246.                             }
  247.                         }
  248.                     }
  249.  
  250.                     if$method == 'reinstall' && in_array'tables'$removeActions )) {
  251.                         ifisset$gBitInstaller->mPackages[$package]['sequences'&& is_array$gBitInstaller->mPackages[$package]['sequences') ) {
  252.                             foreacharray_keys$gBitInstaller->mPackages[$package]['sequences'as $sequenceIdx {
  253.                                 $sql $gBitInstallDb->DropSequence$sequencePrefix.$sequenceIdx );
  254.                                 if (!$sql{
  255.                                     $errors['Failed to drop sequence '.$sequencePrefix.$sequenceIdx;
  256.                                     $failedcommands["DROP SEQUENCE ".$sequencePrefix.$sequenceIdx;
  257.                                 }
  258.                             }
  259.                         }
  260.                     }
  261.  
  262.                     ifisset$gBitInstaller->mPackages[$package]['sequences'&& is_array$gBitInstaller->mPackages[$package]['sequences') ) {
  263.                         // If we use InnoDB for MySql we need this to get sequence tables created correctly.
  264.                         ifisset$_SESSION['use_innodb') ) {
  265.                             if$_SESSION['use_innodb'== TRUE {
  266.                                 $gBitInstallDb->_genSeqSQL "create table %s (id int not null) ENGINE=INNODB";
  267.                             else {
  268.                                 $gBitInstallDb->_genSeqSQL "create table %s (id int not null) ENGINE=MYISAM";
  269.                             }
  270.                         }
  271.                         foreacharray_keys$gBitInstaller->mPackages[$package]['sequences'as $sequenceIdx {
  272.                             $sql $gBitInstallDb->CreateSequence$sequencePrefix.$sequenceIdx$gBitInstaller->mPackages[$package]['sequences'][$sequenceIdx]['start');
  273.                             if (!$sql{
  274.                                 $errors['Failed to create sequence '.$sequencePrefix.$sequenceIdx;
  275.                                 $failedcommands["CREATE SEQUENCE ".$sequencePrefix.$sequenceIdx." START ".$gBitInstaller->mPackages[$package]['sequences'][$sequenceIdx]['start'];
  276.                             }
  277.                         }
  278.                     }
  279.                 elseif$method == 'uninstall' && in_array'tables'$removeActions )) {
  280.                     ifisset$gBitInstaller->mPackages[$package]['sequences'&& is_array$gBitInstaller->mPackages[$package]['sequences') ) {
  281.                         foreacharray_keys$gBitInstaller->mPackages[$package]['sequences'as $sequenceIdx {
  282.                             $sql $gBitInstallDb->DropSequence$sequencePrefix.$sequenceIdx );
  283.                             if (!$sql{
  284.                                 $errors['Failed to drop sequence '.$sequencePrefix.$sequenceIdx;
  285.                                 $failedcommands["DROP SEQUENCE ".$sequencePrefix.$sequenceIdx;
  286.                             }
  287.                         }
  288.                     }
  289.                 }
  290.             }
  291.         }
  292.         $gBitInstallDb->CompleteTrans();
  293.         // Force a reload of all our preferences
  294.         $gBitInstaller->mPrefs '';
  295.         $gBitInstaller->loadConfig();
  296.  
  297.  
  298.  
  299.         // ---------------------- 4. ----------------------
  300.         // manipulate the data in kernel_config
  301.         $gBitInstaller->mDb->StartTrans();
  302.         foreacharray_keys$gBitInstaller->mPackages as $package {
  303.             ifin_array$package$_REQUEST['packages') ) {
  304.                 // remove all the requested settings - this is a bit tricky and might require some more testing
  305.                 // Remove settings if requested
  306.                 ifin_array'settings'$removeActions ) ) {
  307.                     // get a list of permissions used by this package
  308.                     $query "SELECT `perm_name` FROM `".$tablePrefix."users_permissions` WHERE `package`=?";
  309.                     $perms $gBitInstaller->mDb->getCol$queryarray$package ));
  310.                     // we deal with liberty_content_permissions below
  311.                     if defined'ROLE_MODEL' ) ) {
  312.                         $tables array'users_role_permissions''users_permissions' );
  313.                     else {
  314.                         $tables array'users_group_permissions''users_permissions' );
  315.                     }
  316.                     foreach$tables as $table {
  317.                         foreach$perms as $perm {
  318.                             $delete "
  319.                                 DELETE FROM `".$tablePrefix.$table."`
  320.                                 WHERE `perm_name`=?";
  321.                             $ret $gBitInstaller->mDb->query$deletearray$perm ) );
  322.                             if (!$ret{
  323.                                 $errors["Error deleting permission "$perm;
  324.                                 $failedcommands[$delete." ".$perm;
  325.                             }
  326.                         }
  327.                     }
  328.  
  329.                     // list of tables where we store package specific settings
  330.                     $tables array'kernel_config' );
  331.                     foreach$tables as $table {
  332.                         $delete "
  333.                             DELETE FROM `".$tablePrefix.$table."`
  334.                             WHERE `package`=? OR `config_name` LIKE ?";
  335.                         $ret $gBitInstaller->mDb->query$deletearray$package$package."%" ));
  336.                         if (!$ret{
  337.                             $errors["Error deleting confgis for package "$package;
  338.                             $failedcommands[$delete." ".$package;
  339.                         }
  340.                     }
  341.                 }
  342.  
  343.                 // now we can start removing content if requested
  344.                 // lots of foreach loops in here
  345.                 ifin_array'content'$removeActions ) ) {
  346.                     // first we need to work out the package specific content details
  347.                     foreach$gLibertySystem->mContentTypes as $contentType {
  348.                         if$contentType['handler_package'== $package {
  349.                             // first we get a list of content_ids which we can use to scan various tables without content_type_guid column for data
  350.                             $query "SELECT `content_id` FROM `".$tablePrefix."liberty_content` WHERE `content_type_guid`=?";
  351.                             $rmContentIds $gBitInstaller->mDb->getCol$queryarray$contentType['content_type_guid'));
  352.  
  353.                             // list of core tables where bitweaver might store relevant data
  354.                             // firstly, we delete using the content ids
  355.                             // order is important due to the constraints set in the schema
  356.                             $tables array(
  357.                                 'liberty_aliases'             => 'content_id',
  358.                                 'liberty_structures'          => 'content_id',
  359.                                 'liberty_content_hits'        => 'content_id',
  360.                                 'liberty_content_history'     => 'content_id',
  361.                                 'liberty_content_prefs'       => 'content_id',
  362.                                 'liberty_content_links'       => 'to_content_id',
  363.                                 'liberty_content_links'       => 'from_content_id',
  364.                                 'liberty_process_queue'       => 'content_id',
  365.                                 'liberty_content_permissions' => 'content_id',
  366.                                 'users_favorites_map'         => 'favorite_content_id'
  367.                                 // This table needs to be fixed to use content_id instead of page_id
  368.                                 //'liberty_copyrights'          => 'content_id',
  369.  
  370.                                 // liberty comments are tricky. should we remove comments linked to the content being deleted?
  371.                                 // makes sense to me but only if boards are not installed - xing
  372.                                 //'liberty_comments'            => 'root_id',
  373.                             );
  374.                             foreach$rmContentIds as $contentId {
  375.                                 foreach$tables as $table => $column {
  376.                                     $delete "
  377.                                         DELETE FROM `".$tablePrefix.$table."`
  378.                                         WHERE `$column`=?";
  379.                                     $ret $gBitInstaller->mDb->query$deletearray$contentId ));
  380.                                     if (!$ret{
  381.                                         $errors["Error deleting from "$tablePrefxi.$table;
  382.                                         $failedcommands[$delete." ".$contentId;
  383.                                     }
  384.                                 }
  385.                             }
  386.                             // TODO: get a list of tables that have a liberty_content.content_id constraint and delete those entries that we can
  387.                             // remove the entries from liberty_content in the next step
  388.                             // one such example is stars and stars_history - we need to automagically recognise tables with such constraints.
  389.  
  390.                             // TODO: we need an option to physically remove files from the server when we uninstall stuff like fisheye and treasury
  391.                             // 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
  392.  
  393.                             // secondly, we delete using the content type guid
  394.                             // order is important due to the constraints set in the schema
  395.                             $tables array(
  396.                                 'liberty_content',
  397.                                 'liberty_content_types'
  398.                             );
  399.                             foreach$tables as $table {
  400.                                 $delete "
  401.                                     DELETE FROM `".$tablePrefix.$table."`
  402.                                     WHERE `content_type_guid`=?";
  403.                                 $ret $gBitInstaller->mDb->query$deletearray$contentType['content_type_guid'));
  404.                                 if (!$ret{
  405.                                     $errors["Error deleting content type";
  406.                                     $failedcommands[$delete." ".$contentType['content_type_guid'];
  407.                                 }
  408.                             }
  409.                         }
  410.                     }
  411.                 }
  412.  
  413.                 // set installed packages active
  414.                 if$method == 'install' || $method == 'reinstall' {
  415.                     // apparently we need to first remove the vaue from the database to make sure it's set
  416.                     $gBitSystem->storeConfig'package_'.$package NULL );
  417.                     $gBitSystem->storeConfig'package_'.$package 'y'$package );
  418.  
  419.                     // we can assume that the latest upgrade version available for a package is the most current version number for that package
  420.                     if$version $gBitInstaller->getLatestUpgradeVersion$package )) {
  421.                         $gBitSystem->storeVersion$package$version );
  422.                     elseif!empty$gBitInstaller->mPackages[$package]['version')) {
  423.                         $gBitSystem->storeVersion$package$gBitInstaller->mPackages[$package]['version');
  424.                     }
  425.  
  426.                     $gBitInstaller->mPackages$package ]['installed'TRUE;
  427.                     $gBitInstaller->mPackages$package ]['active_switch'TRUE;
  428.                     // we'll default wiki to the home page
  429.                     ifdefined'WIKI_PKG_NAME' && $package == WIKI_PKG_NAME && !$gBitSystem->isFeatureActive'bit_index' )) {
  430.                         $gBitSystem->storeConfig"bit_index"WIKI_PKG_NAMEWIKI_PKG_NAME );
  431.                     }
  432.                 }
  433.             }
  434.         }
  435.  
  436.         // Tonnes of stuff has changed. Force a reload of all our preferences
  437.         $gBitInstaller->mPrefs '';
  438.         $gBitInstaller->loadConfig();
  439.  
  440.  
  441.         $gBitInstaller->mDb->query"DELETE FROM `".BIT_DB_PREFIX."kernel_config` WHERE `package`=?"array$package ) );
  442.         // ---------------------- 5. ----------------------
  443.         // run the defaults through afterwards so we can be sure all tables needed have been created
  444.         foreacharray_keys$gBitInstaller->mPackages as $package {
  445.             if!empty$package )) {
  446.                 ifin_array$package$_REQUEST['packages'|| empty$gBitInstaller->mPackages[$package]['installed'&& !empty$gBitInstaller->mPackages[$package]['required') ) ) {
  447.                     if$method == 'install' || $method == 'reinstall' && in_array'settings'$removeActions ))) {
  448.                         // this list of installed packages is used to show newly installed packages
  449.                         if!empty$gBitInstaller->mPackages[$package]['defaults') ) {
  450.                             foreach$gBitInstaller->mPackages[$package]['defaults'as $def {
  451.                                 if$gBitInstaller->mDb->mType == 'firebird' {
  452.                                     $def preg_replace"/\\\'/""''"$def );
  453.                                 }
  454.                                 $ret $gBitInstaller->mDb->query$def );
  455.                                 if (!$ret{
  456.                                     $errors["Error setting defaults";
  457.                                     $failedcommands[$def;
  458.                                 }
  459.                             }
  460.                         }
  461.                         if!empty$gBitInstaller->mPackages[$package]['default_prefs') ) {
  462.                             foreach$gBitInstaller->mPackages[$package]['default_prefs'as $prefHash {
  463.                                 $ret $gBitInstaller->storeConfig$prefHash['name']$prefHash['value']$prefHash['package']  );
  464.                             }
  465.                         }
  466.                     }
  467.                     // this is to list any processed packages
  468.                     $packageList[$method][$package;
  469.                 }
  470.             }
  471.         }
  472.         $gBitInstaller->mDb->CompleteTrans();
  473.  
  474.  
  475.         // ---------------------- 6. ----------------------
  476.         // register all content types for installed packages
  477.         foreach$gBitInstaller->mContentClasses as $package => $classes ){
  478.             if $gBitInstaller->isPackageInstalled$package ) ){
  479.                 foreach $classes as $objectClass=>$classFile ){
  480.                     require_once$classFile );
  481.                     $tempObject new $objectClass();
  482.                 }
  483.             }
  484.         }
  485.  
  486.  
  487.         // ---------------------- 7. ----------------------
  488.         // Do stuff that only applies during the first install
  489.         $gBitSystem->mDb->StartTrans();
  490.         ifisset$_SESSION['first_install'&& $_SESSION['first_install'== TRUE {
  491.             // set the version of bitweaver in the database
  492.             $gBitSystem->storeVersionNULL$gBitSystem->getBitVersion() );
  493.  
  494.             // Some packages have some special things to take care of here.
  495.             foreach$gBitInstaller->mInstallModules as $mod {
  496.                 $gBitThemes->storeModule$mod );
  497.             }
  498.  
  499.             // Set the default format to get quicktags and content storing working
  500.             $plugin_file LIBERTY_PKG_PATH.'plugins/format.tikiwiki.php';
  501.             ifis_readable$plugin_file ) ) {
  502.                 require_once$plugin_file );
  503.                 // manually set the config settings to avoid problems
  504.                 $gBitSystem->mDb->query"INSERT INTO `".BIT_DB_PREFIX."kernel_config` ( `config_name`, `package`, `config_value` ) VALUES ( 'liberty_plugin_file_".PLUGIN_GUID_TIKIWIKI."', '$plugin_file', '".LIBERTY_PKG_NAME."' )" );
  505.                 $gBitSystem->mDb->query"INSERT INTO `".BIT_DB_PREFIX."kernel_config` ( `config_name`, `package`, `config_value` ) VALUES ( 'liberty_plugin_status_".PLUGIN_GUID_TIKIWIKI."', 'y', '".LIBERTY_PKG_NAME."' )" );
  506.                 // it appear default_format is already set.
  507.                 $gBitSystem->storeConfig'default_format'PLUGIN_GUID_TIKIWIKILIBERTY_PKG_NAME );
  508.             }
  509.  
  510.             // Installing users has some special things to take care of here and needs a separate check.
  511.             ifin_array'users'$_REQUEST['packages') ) {
  512.                 // Creating 'root' user has id=1. phpBB starts with user_id=2, so this is a hack to keep things in sync
  513.                 $storeHash array(
  514.                     'real_name' => 'Root',
  515.                     'login'     => 'root',
  516.                     'password'  => $_SESSION['password'],
  517.                     'email'     => 'root@localhost',
  518.                     'pass_due'  => FALSE,
  519.                     'user_id'   => ROOT_USER_ID
  520.                 );
  521.                 // now let's set up some default data. Group_id's are hardcoded in users/schema_inc defaults
  522.                 if defined'ROLE_MODEL' ) ) {
  523.                     $rootUser new RolePermUser();
  524.                     if$rootUser->store$storeHash ) ) {
  525.                         $gBitUser->mDb->query"INSERT INTO `".BIT_DB_PREFIX."users_roles` (`user_id`, `role_id`, `role_name`,`role_desc`) VALUES ( ".ROOT_USER_ID.", 1, 'Administrators','Site operators')" );
  526.                         $rootUser->addUserToRoleROOT_USER_ID);
  527.                     else {
  528.                         vd'Errors in root user store:'.PHP_EOL );
  529.                         vd$rootUser->mErrors );
  530.                     }
  531.                     $gBitSystem->storeConfig'user_class''RolePermUser'USERS_PKG_NAME );
  532.                     $gBitUser->mDb->query"INSERT INTO `".BIT_DB_PREFIX."users_roles` (`user_id`, `role_id`, `role_name`,`role_desc`) VALUES ( ".ROOT_USER_ID.", ".ANONYMOUS_TEAM_ID.", 'Anonymous','Public users not logged')" );
  533.                     $gBitUser->mDb->query"INSERT INTO `".BIT_DB_PREFIX."users_roles` (`user_id`, `role_id`, `role_name`,`role_desc`) VALUES ( ".ROOT_USER_ID.", 2, 'Editors','Site  Editors')" );
  534.                     $gBitUser->mDb->query"INSERT INTO `".BIT_DB_PREFIX."users_roles` (`user_id`, `role_id`, `role_name`,`role_desc`,`is_default`) VALUES ( ".ROOT_USER_ID.", 3, 'Registered', 'Users logged into the system', 'y')" );
  535.                 else {
  536.                     $rootUser new BitPermUser();
  537.                     if$rootUser->store$storeHash ) ) {
  538.                         $gBitUser->mDb->query"INSERT INTO `".BIT_DB_PREFIX."users_groups` (`user_id`, `group_id`, `group_name`,`group_desc`) VALUES ( ".ROOT_USER_ID.", 1, 'Administrators','Site operators')" );
  539.                         $rootUser->addUserToGroupROOT_USER_ID);
  540.                     else {
  541.                         vd'Errors in root user store:'.PHP_EOL );
  542.                         vd$rootUser->mErrors );
  543.                     }
  544.                     $gBitUser->mDb->query"INSERT INTO `".BIT_DB_PREFIX."users_groups` (`user_id`, `group_id`, `group_name`,`group_desc`) VALUES ( ".ROOT_USER_ID.", ".ANONYMOUS_GROUP_ID.", 'Anonymous','Public users not logged')" );
  545.                     $gBitUser->mDb->query"INSERT INTO `".BIT_DB_PREFIX."users_groups` (`user_id`, `group_id`, `group_name`,`group_desc`) VALUES ( ".ROOT_USER_ID.", 2, 'Managers','Site Managers')" );
  546.                     $gBitUser->mDb->query"INSERT INTO `".BIT_DB_PREFIX."users_groups` (`user_id`, `group_id`, `group_name`,`group_desc`,`is_default`) VALUES ( ".ROOT_USER_ID.", 3, 'Registered', 'Users logged into the system', 'y')" );
  547.                 }
  548.  
  549.                 $gBitUser->assignLevelPermissionsANONYMOUS_TEAM_ID'basic' );
  550.                 $gBitUser->assignLevelPermissions3'registered' );
  551.                 $gBitUser->assignLevelPermissions2'editors' );
  552.                 $gBitUser->assignLevelPermissions1'admin' );
  553.  
  554.                 // Create 'Anonymous' user has id= -1 just like phpBB
  555.                 $storeHash array(
  556.                     'real_name'        => 'Guest',
  557.                     'login'            => 'guest',
  558.                     'password'         => $_SESSION['password'],
  559.                     'email'            => 'guest@localhost',
  560.                     'pass_due'         => FALSE,
  561.                     'user_id'          => ANONYMOUS_USER_ID,
  562.                     'default_role_id'  => ANONYMOUS_TEAM_ID
  563.                 );
  564.                 if defined'ROLE_MODEL' ) ) {
  565.                     $anonUser new RolePermUser();
  566.                     if$anonUser->store$storeHash ) ) {
  567.                         // Remove anonymous from registered group
  568.                         $regRoleId $anonUser->roleExists'Registered'ROOT_USER_ID );
  569.                         $anonUser->removeUserFromRoleANONYMOUS_USER_ID$regRoleId );
  570.                         $anonUser->addUserToRoleANONYMOUS_USER_IDANONYMOUS_TEAM_ID);
  571.                     }
  572.                 else {
  573.                     $anonUser new BitPermUser();
  574.                     if$anonUser->store$storeHash ) ) {
  575.                         // Remove anonymous from registered group
  576.                         $regGroupId $anonUser->groupExists'Registered'ROOT_USER_ID );
  577.                         $anonUser->removeUserFromGroupANONYMOUS_USER_ID$regGroupId );
  578.                         $anonUser->addUserToGroupANONYMOUS_USER_IDANONYMOUS_GROUP_ID);
  579.                     }
  580.                 }
  581.  
  582.                 // Create 'Admin' user has id= 2
  583.                 $storeHash array(
  584.                     'real_name' => $_SESSION['real_name'],
  585.                     'login'     => $_SESSION['login'],
  586.                     'password'  => $_SESSION['password'],
  587.                     'email'     => $_SESSION['email'],
  588.                     'pass_due'  => FALSE
  589.                 );
  590.                 if defined'ROLE_MODEL' ) ) {
  591.                     $adminUser new RolePermUser();
  592.                     if$adminUser->store$storeHash ) ) {
  593.                         // add user to admin role
  594.                         $adminUser->addUserToRole$adminUser->mUserId);
  595.                         // set admin role as default
  596.                         $adminUser->storeUserDefaultRole$adminUser->mUserId);
  597.                     else {
  598.                         vd$adminUser->mErrors )die;
  599.                     }
  600.                 else {
  601.                     $adminUser new BitPermUser();
  602.                     if$adminUser->store$storeHash ) ) {
  603.                         // add user to admin group
  604.                         $adminUser->addUserToGroup$adminUser->mUserId);
  605.                         // set admin group as default
  606.                         $adminUser->storeUserDefaultGroup$adminUser->mUserId);
  607.                     else {
  608.                         vd$adminUser->mErrors )die;
  609.                     }
  610.                 }
  611.  
  612.                 // kill admin info in $_SESSION
  613. //                unset( $_SESSION['real_name'] );
  614. //                unset( $_SESSION['login'] );
  615. //                unset( $_SESSION['password'] );
  616. //                unset( $_SESSION['email'] );
  617.             }
  618.         }
  619.  
  620.  
  621.  
  622.         // ---------------------- 8. ----------------------
  623.         // woo! we're done with the installation bit - below here is some generic installer stuff
  624.         $gBitSmarty->assign'next_step'$step );
  625.  
  626.         // display list of installed packages
  627.         asort$packageList );
  628.         $gBitSmarty->assign'packageList'$packageList );
  629.  
  630.         // enter some log information to say we've initialised the system
  631.         if!empty$failedcommands ) ) {
  632.             $gBitSmarty->assign'errors'$errors);
  633.             $gBitSmarty->assign'failedcommands'$failedcommands);
  634.             $gBitSystem->mDb->RollbackTrans();
  635.         else {
  636.             $gBitSystem->mDb->CompleteTrans();
  637.         }
  638.  
  639.         // display the confirmation page
  640.         $app '_done';
  641.     else {
  642.         // if we can't connect to the db, move back 2 steps
  643.         header"Location: ".$_SERVER['SCRIPT_NAME']."?step=".$step );
  644.     }
  645. elseif!empty$_REQUEST['submit_packages') ) {
  646.     // No packages to install so just move to the next step.
  647.     $gBitSmarty->assign'next_step'$step );
  648.     $app '_done';
  649. }
  650. ?>

Documentation generated on Wed, 29 Jul 2015 13:56:45 +0000 by phpDocumentor 1.5.0-lsces