summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBharat Mediratta <bharat@menalto.com>2009-03-20 08:22:57 +0000
committerBharat Mediratta <bharat@menalto.com>2009-03-20 08:22:57 +0000
commit6df1dffed1e2eef2690444e044c2adb1a9bbca51 (patch)
tree9004fc1557be02c9ba3f812018342ae0325abe7d
parent06baa24dd6e8e78df0f29ffcff5a808e134331d8 (diff)
Do some data normalization so that the install files will have stable
ordering and known values. This way subsequent packaging runs won't have any differences unless there's a real data change.
-rw-r--r--core/controllers/scaffold.php32
-rw-r--r--installer/init_var.php4
-rw-r--r--installer/install.sql6
3 files changed, 30 insertions, 12 deletions
diff --git a/core/controllers/scaffold.php b/core/controllers/scaffold.php
index 63b00f2d..f3f3605b 100644
--- a/core/controllers/scaffold.php
+++ b/core/controllers/scaffold.php
@@ -287,6 +287,10 @@ class Scaffold_Controller extends Template_Controller {
module::$modules = array();
$db->clear_cache();
+ // Use a known random seed so that subsequent packaging runs will reuse the same random
+ // numbers, keeping our install.sql file more stable.
+ srand(0);
+
core_installer::install(true);
module::load_modules();
@@ -294,6 +298,7 @@ class Scaffold_Controller extends Template_Controller {
"search", "slideshow", "tag") as $module_name) {
module::install($module_name);
}
+
url::redirect("scaffold/dump_database");
}
@@ -305,6 +310,7 @@ class Scaffold_Controller extends Template_Controller {
$db = Database::instance();
$db->query("TRUNCATE {sessions}");
$db->query("TRUNCATE {logs}");
+ $db->update("users", array("password" => ""), array("id" => 1));
$db->update("users", array("password" => ""), array("id" => 2));
$dbconfig = Kohana::config('database.default');
@@ -326,12 +332,18 @@ class Scaffold_Controller extends Template_Controller {
return;
}
- // Post-process the sql file to support prefixes
+ // Post-process the sql file
$buf = "";
+ $root_timestamp = ORM::factory("item", 1)->created;
foreach (file($sql_file) as $line) {
- $buf .= preg_replace(
+ // Prefix tables
+ $line = preg_replace(
"/(CREATE TABLE|IF EXISTS|INSERT INTO) `{$dbconfig['table_prefix']}(\w+)`/", "\\1 {\\2}",
$line);
+
+ // Normalize dates
+ $line = preg_replace("/,$root_timestamp,/", ",NOW(),", $line);
+ $buf .= $line;
}
$fd = fopen($sql_file, "wb");
fwrite($fd, $buf);
@@ -353,9 +365,7 @@ class Scaffold_Controller extends Template_Controller {
return;
}
- $fd = fopen($var_file, "w");
- fwrite($fd, "<?php defined(\"SYSPATH\") or die(\"No direct script access.\") ?>\n");
- fwrite($fd, "<?php\n");
+ $paths = array();
foreach($objects as $name => $file){
if ($file->getBasename() == "database.php") {
continue;
@@ -364,14 +374,22 @@ class Scaffold_Controller extends Template_Controller {
}
if ($file->isDir()) {
- $path = "VARPATH . \"" . substr($name, strlen(VARPATH)) . "\"";
- fwrite($fd, "!file_exists($path) && mkdir($path);\n");
+ $paths[] = "VARPATH . \"" . substr($name, strlen(VARPATH)) . "\"";
} else {
// @todo: serialize non-directories
print "Unknown file: $name";
return;
}
}
+ // Sort the paths so that the var file is stable
+ sort($paths);
+
+ $fd = fopen($var_file, "w");
+ fwrite($fd, "<?php defined(\"SYSPATH\") or die(\"No direct script access.\") ?>\n");
+ fwrite($fd, "<?php\n");
+ foreach ($paths as $path) {
+ fwrite($fd, "!file_exists($path) && mkdir($path);\n");
+ }
fclose($fd);
url::redirect("scaffold");
}
diff --git a/installer/init_var.php b/installer/init_var.php
index b1ecf995..f4637016 100644
--- a/installer/init_var.php
+++ b/installer/init_var.php
@@ -2,7 +2,7 @@
<?php
!file_exists(VARPATH . "albums") && mkdir(VARPATH . "albums");
!file_exists(VARPATH . "logs") && mkdir(VARPATH . "logs");
-!file_exists(VARPATH . "uploads") && mkdir(VARPATH . "uploads");
+!file_exists(VARPATH . "modules") && mkdir(VARPATH . "modules");
!file_exists(VARPATH . "resizes") && mkdir(VARPATH . "resizes");
!file_exists(VARPATH . "thumbs") && mkdir(VARPATH . "thumbs");
-!file_exists(VARPATH . "modules") && mkdir(VARPATH . "modules");
+!file_exists(VARPATH . "uploads") && mkdir(VARPATH . "uploads");
diff --git a/installer/install.sql b/installer/install.sql
index f157df78..d8f6017c 100644
--- a/installer/install.sql
+++ b/installer/install.sql
@@ -147,7 +147,7 @@ CREATE TABLE {items} (
KEY `random` (`rand_key`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8;
SET character_set_client = @saved_cs_client;
-INSERT INTO {items} VALUES (NULL,1237193225,'',NULL,1,1,1,NULL,NULL,NULL,0,NULL,NULL,1,2,NULL,NULL,1,'Gallery','album',1237193225,0,NULL,NULL,'id','ASC',1,1);
+INSERT INTO {items} VALUES (NULL,NOW(),'',NULL,1,1,1,NULL,NULL,NULL,0,NULL,NULL,1,2,NULL,NULL,1,'Gallery','album',NOW(),0,NULL,NULL,'id','ASC',1,1);
DROP TABLE IF EXISTS {items_tags};
SET @saved_cs_client = @@character_set_client;
SET character_set_client = utf8;
@@ -312,7 +312,7 @@ CREATE TABLE {users} (
UNIQUE KEY `hash` (`hash`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8;
SET character_set_client = @saved_cs_client;
-INSERT INTO {users} VALUES (1,'guest','Guest User','jZstacc6b8aca100c7d53663c65ef1e3428c',0,0,NULL,0,1,NULL,NULL,NULL),(2,'admin','Gallery Administrator','',0,0,NULL,1,0,NULL,NULL,NULL);
+INSERT INTO {users} VALUES (1,'guest','Guest User','',0,0,NULL,0,1,NULL,NULL,NULL),(2,'admin','Gallery Administrator','',0,0,NULL,1,0,NULL,NULL,NULL);
DROP TABLE IF EXISTS {vars};
SET @saved_cs_client = @@character_set_client;
SET character_set_client = utf8;
@@ -325,4 +325,4 @@ CREATE TABLE {vars} (
UNIQUE KEY `module_name` (`module_name`,`name`)
) ENGINE=InnoDB AUTO_INCREMENT=13 DEFAULT CHARSET=utf8;
SET character_set_client = @saved_cs_client;
-INSERT INTO {vars} VALUES (1,'core','active_site_theme','default'),(2,'core','active_admin_theme','admin_default'),(3,'core','page_size','9'),(4,'core','thumb_size','200'),(5,'core','resize_size','640'),(6,'core','default_locale','en_US'),(7,'core','graphics_toolkit','imagemagick'),(8,'core','graphics_toolkit_path','/usr/bin'),(9,'core','blocks_dashboard_sidebar','a:4:{i:757340436;a:2:{i:0;s:4:\"core\";i:1;s:11:\"block_adder\";}i:454213168;a:2:{i:0;s:4:\"core\";i:1;s:5:\"stats\";}i:1443307249;a:2:{i:0;s:4:\"core\";i:1;s:13:\"platform_info\";}i:997696381;a:2:{i:0;s:4:\"core\";i:1;s:12:\"project_news\";}}'),(10,'core','blocks_dashboard_center','a:4:{i:1396928874;a:2:{i:0;s:4:\"core\";i:1;s:7:\"welcome\";}i:454790507;a:2:{i:0;s:4:\"core\";i:1;s:12:\"photo_stream\";}i:902866042;a:2:{i:0;s:4:\"core\";i:1;s:11:\"log_entries\";}i:276132468;a:2:{i:0;s:7:\"comment\";i:1;s:15:\"recent_comments\";}}'),(11,'core','version','3.0'),(12,'comment','spam_caught','0');
+INSERT INTO {vars} VALUES (1,'core','active_site_theme','default'),(2,'core','active_admin_theme','admin_default'),(3,'core','page_size','9'),(4,'core','thumb_size','200'),(5,'core','resize_size','640'),(6,'core','default_locale','en_US'),(7,'core','graphics_toolkit','imagemagick'),(8,'core','graphics_toolkit_path','/usr/bin'),(9,'core','blocks_dashboard_sidebar','a:4:{i:1804289383;a:2:{i:0;s:4:\"core\";i:1;s:11:\"block_adder\";}i:846930886;a:2:{i:0;s:4:\"core\";i:1;s:5:\"stats\";}i:1681692777;a:2:{i:0;s:4:\"core\";i:1;s:13:\"platform_info\";}i:1714636915;a:2:{i:0;s:4:\"core\";i:1;s:12:\"project_news\";}}'),(10,'core','blocks_dashboard_center','a:4:{i:1957747793;a:2:{i:0;s:4:\"core\";i:1;s:7:\"welcome\";}i:424238335;a:2:{i:0;s:4:\"core\";i:1;s:12:\"photo_stream\";}i:719885386;a:2:{i:0;s:4:\"core\";i:1;s:11:\"log_entries\";}i:1649760492;a:2:{i:0;s:7:\"comment\";i:1;s:15:\"recent_comments\";}}'),(11,'core','version','3.0 Alpha 3'),(12,'comment','spam_caught','0');