From 4faa4b8dc479ba7ea45db9ad1e4d9cd2b19d17be Mon Sep 17 00:00:00 2001 From: james Date: Wed, 23 Jun 2010 16:06:01 +0000 Subject: [PATCH] Migrate all dates to use conferences ONLY, instead of dual conference/FAIRYEAR setup --- common.inc.php | 6 +++--- config/dates.php | 36 ++++++++++-------------------------- db/db.code.version.txt | 2 +- db/db.update.191.php | 16 ++++++++++++++++ db/db.update.191.sql | 1 + 5 files changed, 31 insertions(+), 30 deletions(-) create mode 100644 db/db.update.191.php create mode 100644 db/db.update.191.sql diff --git a/common.inc.php b/common.inc.php index b490d2b4..d319ce28 100644 --- a/common.inc.php +++ b/common.inc.php @@ -103,7 +103,7 @@ if(!mysql_select_db($DBNAME)) @mysql_query("SET NAMES utf8"); //find out the fair year and any other 'year=0' configuration parameters (things that dont change as the years go on) -$q=@mysql_query("SELECT * FROM config WHERE year='0'"); +$q=@mysql_query("SELECT * FROM config WHERE conferences_id=0 OR year=0"); //we might get an error if installation step 2 is not done (ie, the config table doesnt even exist) if(mysql_error()) @@ -242,7 +242,7 @@ if(intval($_SESSION['conferenceid'])>0) { } //now pull the rest of the configuration -$q=mysql_query("SELECT * FROM config WHERE year='".$config['FAIRYEAR']."'"); +$q=mysql_query("SELECT * FROM config WHERE conferences_id='".$conference['id']."'"); while($r=mysql_fetch_object($q)) { $config[$r->var]=$r->val; } @@ -251,7 +251,7 @@ while($r=mysql_fetch_object($q)) { if($conference['id']) $q=mysql_query("SELECT * FROM dates WHERE conferences_id='".$conference['id']."'"); else - $q=mysql_query("SELECT * FROM dates WHERE year='".$config['FAIRYEAR']."'"); + $config['dates']=array(); while($r=mysql_fetch_object($q)) { $config['dates'][$r->name]=$r->date; diff --git a/config/dates.php b/config/dates.php index 818527a3..38c34fa9 100644 --- a/config/dates.php +++ b/config/dates.php @@ -31,7 +31,7 @@ ,"important_dates" ); -$q=mysql_query("SELECT * FROM dates WHERE year='-1'"); +$q=mysql_query("SELECT * FROM dates WHERE conferences_id='-1'"); while($r=mysql_fetch_object($q)) { $defaultdates[$r->name]=$r; } @@ -87,12 +87,7 @@ $possibledates['scienceolympics'] = array('fairdate' => array() , $dates=$possibledates[$conference['type']]; /* Now copy the SQL data into the above array */ -if($conference['id']>0) { - $q=mysql_query("SELECT * FROM dates WHERE conferences_id='".$conference['id']."' ORDER BY date"); -} -else { - $q=mysql_query("SELECT * FROM dates WHERE year='".$config['FAIRYEAR']."' ORDER BY date"); -} + $q=mysql_query("SELECT * FROM dates WHERE conferences_id='".$conference['id']."' ORDER BY date"); while($r=mysql_fetch_object($q)) { //check if its a date we dont care about if(!is_array($dates[$r->name])) @@ -142,25 +137,14 @@ foreach($dates as $dn=>$d) { if(!$d['id']) { $def=$defaultdates[$dn]; //hmm if we dont have a record for this date this year, INSERT the sql from the default - if($conference['id']>0) { - mysql_query("INSERT INTO dates (date,name,description,year,conferences_id) VALUES ( - '".mysql_real_escape_string($def->date)."', - '".mysql_real_escape_string($dn)."', - '".mysql_real_escape_string($def->description)."', - 0, - '".$conference['id']."' - )"); - echo mysql_error(); - } - else { - mysql_query("INSERT INTO dates (date,name,description,year,conferences_id) VALUES ( - '".mysql_real_escape_string($def->date)."', - '".mysql_real_escape_string($dn)."', - '".mysql_real_escape_string($def->description)."', - '".$config['FAIRYEAR']."', - 0 - )"); - } + mysql_query("INSERT INTO dates (date,name,description,year,conferences_id) VALUES ( + '".mysql_real_escape_string($def->date)."', + '".mysql_real_escape_string($dn)."', + '".mysql_real_escape_string($def->description)."', + 0, + '".$conference['id']."' + )"); + echo mysql_error(); $d['id']=mysql_insert_id(); $d['description']=$def->description; $d['date']=$def->date; diff --git a/db/db.code.version.txt b/db/db.code.version.txt index 598ed30e..88b2e783 100644 --- a/db/db.code.version.txt +++ b/db/db.code.version.txt @@ -1 +1 @@ -190 +191 diff --git a/db/db.update.191.php b/db/db.update.191.php new file mode 100644 index 00000000..fbe793e4 --- /dev/null +++ b/db/db.update.191.php @@ -0,0 +1,16 @@ +0"); + while($r=mysql_fetch_object($q)) { + echo " Updating dates for year={$r->year} to conferences_id={$r->id}\n"; + mysql_query("UPDATE dates SET conferences_id='$r->id' WHERE year='$r->year'"); + } +} + +function db_update_191_post() +{ +} + +?> diff --git a/db/db.update.191.sql b/db/db.update.191.sql new file mode 100644 index 00000000..5f8fa038 --- /dev/null +++ b/db/db.update.191.sql @@ -0,0 +1 @@ +UPDATE dates SET conferences_id=-1 WHERE year=-1;