Example #1
0
/**
 * This function will check if an upgrade of the database scheme is needed.
 * It is generic for all database layers.
 */
function event_logging_db_install()
{
    $PHORUM = $GLOBALS["PHORUM"];
    $version = isset($PHORUM["mod_event_logging_installed"]) ? $PHORUM["mod_event_logging_installed"] : 0;
    while ($version < EVENT_LOGGING_DB_VERSION) {
        // Initialize the settings array that we will be saving.
        $version++;
        $settings = array("mod_event_logging_installed" => $version);
        $sqlfile = "./mods/event_logging/db/" . $PHORUM["DBCONFIG"]["type"] . "/{$version}.php";
        if (!file_exists($sqlfile)) {
            print "<b>Unexpected situation on installing " . "the Event Logging module</b>: " . "unable to find the database schema setup script " . htmlspecialchars($sqlfile);
            return false;
        }
        $sqlqueries = array();
        include $sqlfile;
        if (count($sqlqueries) == 0) {
            print "<b>Unexpected situation on installing " . "the Event Logging module</b>: could not read any SQL " . "queries from file " . htmlspecialchars($sqlfile);
            return false;
        }
        $err = phorum_db_run_queries($sqlqueries);
        if ($err) {
            print "<b>Unexpected situation on installing " . "the Event Logging module</b>: running the " . "install queries from file " . htmlspecialchars($sqlfile) . " failed. The error was " . htmlspecialchars($err);
            return false;
        }
        // Save our settings.
        if (!phorum_db_update_settings($settings)) {
            print "<b>Unexpected situation on installing " . "the Event Logging module</b>: updating the " . "mod_event_logging_installed setting failed";
            return false;
        }
    }
    return true;
}
Example #2
0
function spamhurdles_db_install()
{
    $version = isset($GLOBALS["PHORUM"]["mod_spamhurdles_installed"]) ? $GLOBALS["PHORUM"]["mod_spamhurdles_installed"] : 0;
    while ($version < SPAMHURDLES_DB_VERSION) {
        // Initialize the settings array that we will be saving.
        $version++;
        $settings = array("mod_spamhurdles_installed" => $version);
        $sqlfile = "./mods/spamhurdles/db/" . $GLOBALS["PHORUM"]["DBCONFIG"]["type"] . "/{$version}.php";
        if (!file_exists($sqlfile)) {
            print "<b>Unexpected situation on installing " . "the Spam Hurdles module</b>: unable to find the database " . "scheme setup script " . htmlspecialchars($sqlfile);
            return false;
        }
        $sqlqueries = array();
        include $sqlfile;
        if (count($sqlqueries) == 0) {
            print "<b>Unexpected situation on installing " . "the Spam Hurdles module</b>: could not read any SQL " . "queries from file " . htmlspecialchars($sqlfile);
            return false;
        }
        $err = phorum_db_run_queries($sqlqueries);
        if ($err) {
            print "<b>Unexpected situation on installing " . "the Spam Hurdles module</b>: running the " . "install queries from file " . htmlspecialchars($sqlfile) . " failed: " . htmlspecialchars($err);
            return false;
        }
        // Save our settings.
        if (!phorum_db_update_settings($settings)) {
            print "<b>Unexpected situation on installing " . "the Spam Hurdles module</b>: updating the " . "mod_spamhurdles_installed setting failed";
            return false;
        }
    }
    return true;
}
Example #3
0
function spamhurdles_db_init()
{
    global $PHORUM;
    $layerpath = "./mods/spamhurdles/db/{$PHORUM["DBCONFIG"]["type"]}";
    // Allow db layers to provide an initialization script of their own.
    // The main goal for this script is to allow a db layer to override the
    // $PHORUM['spamhurdles_table'] variable.
    if (file_exists("{$layerpath}/db.php")) {
        require_once "{$layerpath}/db.php";
    }
    $version = isset($PHORUM["mod_spamhurdles_installed"]) ? $PHORUM["mod_spamhurdles_installed"] : 0;
    while ($version < SPAMHURDLES_DB_VERSION) {
        // Initialize the settings array that we will be saving.
        $version++;
        $settings = array("mod_spamhurdles_installed" => $version);
        $sqlfile = "{$layerpath}/{$version}.php";
        if (!file_exists($sqlfile)) {
            print "<b>Unexpected situation on installing " . "the Spam Hurdles module</b>: unable to find the database " . "scheme setup script " . htmlspecialchars($sqlfile);
            return false;
        }
        $sqlqueries = array();
        include $sqlfile;
        if (count($sqlqueries) == 0) {
            print "<b>Unexpected situation on installing " . "the Spam Hurdles module</b>: could not read any SQL " . "queries from file " . htmlspecialchars($sqlfile);
            return false;
        }
        $err = phorum_db_run_queries($sqlqueries);
        if ($err) {
            print "<b>Unexpected situation on installing " . "the Spam Hurdles module</b>: running the " . "install queries from file " . htmlspecialchars($sqlfile) . " failed: " . htmlspecialchars($err);
            return false;
        }
        // Save our settings.
        if (!phorum_db_update_settings($settings)) {
            print "<b>Unexpected situation on installing " . "the Spam Hurdles module</b>: updating the " . "mod_spamhurdles_installed setting failed";
            return false;
        }
    }
    return true;
}
Example #4
0
    function phorum_upgrade_tables($fromversion,$toversion) {

          $PHORUM=$GLOBALS['PHORUM'];

          if(empty($fromversion) || empty($toversion)){
              die("Something is wrong with the upgrade script.  Please contact the Phorum Dev Team. ($fromversion,$toversion)");
          }

          $msg="";
          $upgradepath="./include/db/upgrade/{$PHORUM['DBCONFIG']['type']}/";

          // read in all existing files
          $dh=opendir($upgradepath);
          $upgradefiles=array();
          while ($file = readdir ($dh)) {
              if (substr($file,-4,4) == ".php") {
                  $upgradefiles[]=$file;
              }
          }
          unset($file);
          closedir($dh);

          // sorting by number
          sort($upgradefiles,SORT_NUMERIC);
          reset($upgradefiles);

          // advance to current version
          while(list($key,$val)=each($upgradefiles)) {
              if($val == $fromversion.".php")
              break;
          }



          // get the file for the next version (which we will upgrade to)
          list($dump,$file) = each($upgradefiles);

          // extract the pure version, needed as internal version
          $pure_version = basename($file,".php");

          if(empty($pure_version)){
              die("Something is wrong with the upgrade script.  Please contact the Phorum Dev Team. ($fromversion,$toversion)");
          }


          $upgradefile=$upgradepath.$file;

          if(file_exists($upgradefile)) {
              if (! is_readable($upgradefile))
                die("$upgradefile is not readable. Make sure the file has got the neccessary permissions and try again.");

              $msg.="Upgrading from db-version $fromversion to $pure_version ... ";
              $upgrade_queries=array();
              include($upgradefile);
              $err=phorum_db_run_queries($upgrade_queries);
              if($err){
                  $msg.= "an error occured: $err ... try to continue.<br />\n";
              } else {
                  $msg.= "done.<br />\n";
              }
              $GLOBALS["PHORUM"]["internal_version"]=$pure_version;
              phorum_db_update_settings(array("internal_version"=>$pure_version));
          } else {
              $msg="Ooops, the upgradefile is missing. How could this happen?";
          }

          return $msg;
    }
Example #5
0
/**
 * Perform the upgrade for a single upgrade file.
 *
 * @param $upgrades - An upgrade description. One element from the array
 *                    as returned by phorum_dbupgrade_getupgrades().
 * @param $update_internal_version - whether to update the internal version
 *                    for Phorum or not. This one is TRUE by default.
 *                    It can be used by scripts that have to re-run an old
 *                    single upgrade file and for which the internal version
 *                    should not be put back to an old value.
 * @return $msg - Describes the results of the upgrade.
 */
function phorum_dbupgrade_run($upgrade, $update_internal_version = TRUE)
{
    $PHORUM = $GLOBALS["PHORUM"];
    $version = $upgrade["version"];
    $type = $upgrade["type"];
    $upgradefile = $upgrade["file"];
    $versionvar = $type == 'patch' ? 'internal_patchlevel' : 'internal_version';
    // Find the version from which we're upgrading.
    $fromversion = $PHORUM[$versionvar];
    // Executing large, long running scripts can result in problems,
    // in case the script hits PHP resource boundaries. Here we try
    // to prepare the PHP environment for the upgrade. Unfortunately,
    // if the server is running with safe_mode enabled, we cannot
    // change the execution time and memory limits.
    if (!ini_get('safe_mode')) {
        set_time_limit(0);
        ini_set("memory_limit", "64M");
    }
    // Check if the upgradefile is readable.
    if (file_exists($upgradefile) && is_readable($upgradefile)) {
        // Initialize the return message.
        if (!$update_internal_version) {
            $msg = "Installing patch {$version} ...<br/>\n";
        } elseif ($fromversion == '1111111111') {
            $msg = "Upgrading to patch level {$version} ...<br/>\n";
        } else {
            $msg = "Upgrading from " . ($type == "patch" ? "patch level " : "database version ") . "{$fromversion} to {$version} ...<br/>\n";
        }
        // Load the upgrade file. The upgrade file should fill the
        // $upgrade_queries array with the necessary queries to run.
        $upgrade_queries = array();
        include $upgradefile;
        // Run the upgrade queries.
        $err = phorum_db_run_queries($upgrade_queries);
        if ($err !== NULL) {
            $msg .= "An error occured during this upgrade:<br/><br/>\n" . "<span style=\"color:red\">{$err}</span><br/><br/>\n" . "Please make note of this error and contact the " . "Phorum Dev Team for help.\nYou can try to continue " . "with the rest of the upgrade.<br/>\n";
        } else {
            $msg .= "The upgrade was successful.<br/>\n";
        }
        // Update the upgrade version info.
        if ($update_internal_version) {
            $GLOBALS["PHORUM"][$versionvar] = $version;
            phorum_db_update_settings(array($versionvar => $version));
        }
        return $msg;
    } else {
        return "The upgrade file " . htmlspecialchars($upgradefile) . " " . "cannot be opened by Phorum for reading. Please check " . "the file permissions for this file and try again.";
    }
}
Example #6
0
    }


    $upgradefile=$upgradepath.$file;

    if(file_exists($upgradefile)) {
        echo "Upgrading from db-version $fromversion to $pure_version ... \n";
        flush();

        if (! is_readable($upgradefile))
        die("$upgradefile is not readable. Make sure the file has got the neccessary permissions and try again.");


        $upgrade_queries=array();
        include($upgradefile);
        $err=phorum_db_run_queries($upgrade_queries);
        if($err){
            echo "an error occured: $err ... try to continue.\n";
        } else {
            echo "done.\n";
        }
        $GLOBALS["PHORUM"]["internal_version"]=$pure_version;
        phorum_db_update_settings(array("internal_version"=>$pure_version));
    } else {
        echo "Ooops, the upgradefile is missing. How could this happen?\n";
    }

    $fromversion=$pure_version;

}
?>
Example #7
0
/**
 * split thread
 */
function phorum_db_split_thread($message, $forum_id)
{
    settype($message, "int");
    settype($forum_id, "int");

    if($message > 0 && $forum_id > 0){
        // get message tree for update thread id
        $tree =phorum_db_get_messagetree($message, $forum_id);
        $queries =array();
        $queries[0]="UPDATE {$GLOBALS['PHORUM']['message_table']} SET thread='$message', parent_id='0' WHERE message_id ='$message'";
        $queries[1]="UPDATE {$GLOBALS['PHORUM']['message_table']} SET thread='$message' WHERE message_id IN ($tree)";
        phorum_db_run_queries($queries);
    }
}
// YOU NEED TO MOVE THIS SCRIPT TO YOUR PHORUM-DIRECTORY

define('phorum_page', 'rebuild_search_table');

if(!file_exists('./common.php')) {
    echo "You didn't move this script to your phorum-directory!\n";
    exit();
}

include './common.php';

if (! ini_get('safe_mode')) {
    set_time_limit(0);
    ini_set("memory_limit","64M");
}

echo "Rebuilding search-table ...\n";

$sql=array();
$sql[]="truncate {$PHORUM['search_table']}";
$sql[]="insert into {$PHORUM['search_table']} (message_id,search_text,forum_id) select message_id, concat(author, ' | ', subject, ' | ', body), forum_id from {$PHORUM['message_table']}";

phorum_db_run_queries($sql);

flush();
echo "Rebuilding search-table finished successfully if no errors were logged above.\n";


?>