Location: PHPKode > projects > photolibrary > update.php
<?PHP
/*
   [Start: Program Information Header]

    Name    : Photolibrary: Update page
    Purpose : Auto update page
    Syntax  :

   [End: Program Information Header]

   [Start: Author Information Header]

    Name    : James D. Forrester
    E-mail  : hide@address.com

    Name    : Ed Sanders
    E-mail  : hide@address.com

   [End: Author Information Header]
*/

require('include.initialise.php');

$page_title = language('update');
include('include.menu.php');

$queries = array();
$queries['1.000'] = '
ALTER TABLE `photostocategories` CHANGE COLUMN `hash` `hash` varchar(32) NOT NULL;
';
$queries['1.001'] = '
ALTER TABLE `accounts` DROP PRIMARY KEY;
ALTER TABLE `accounts` ADD COLUMN `user_id` int(8) unsigned NOT NULL AUTO_INCREMENT FIRST, ADD PRIMARY KEY (`user_id`);
ALTER TABLE `accounts` ADD COLUMN `admin` tinyint(1) unsigned NOT NULL DEFAULT 0;
UPDATE `accounts` SET `admin` = 1;
ALTER TABLE `photocomments` ADD INDEX `hash` (`hash`(32));
ALTER TABLE `photostocategories`  ADD INDEX `category` (`category`);
ALTER TABLE `categories` ADD INDEX `parent` (`parent`);
';
$queries['1.003'] = '
ALTER TABLE `photos` ADD INDEX `session` (`session`);
ALTER TABLE `photos` ADD COLUMN `comments` int(8) unsigned NOT NULL DEFAULT 0;
ALTER TABLE `errorlog` ADD COLUMN `user_id` int(8) unsigned NOT NULL DEFAULT 0;
UPDATE `errorlog`, `accounts` SET `errorlog`.`user_id` = `accounts`.`user_id` WHERE `errorlog`.`user` = `accounts`.`username`;
ALTER TABLE `errorlog` DROP COLUMN `user`;
';
$queries['1.006'] = '
ALTER TABLE `accounts` ADD UNIQUE INDEX `username` (`username`(32));
ALTER TABLE `photocomments` CHANGE COLUMN `timestamp` `timestamp` datetime NOT NULL;
';

format_html('Runnning updates:<ul>');
foreach($queries as $version => $query)
  if($version >= $settings['build'] and $version < $this_build)
    run_sql($queries[$version], true, true);

run_sql("REPLACE INTO `settings` (`variable`, `value`) VALUES ('build', '$this_build');", true, true);

format_html('</ul>');

run_sql('data_structure.sql');
run_sql('language.sql');
update_language();
update_comments();

format_html('Database update complete, now visit <a href="settings.php">settings</a> and re-save.<br />');

include('include.footer.php');

?>
Return current item: photolibrary