This repository has been archived by the owner on May 19, 2020. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
man, fuck one click upgrade. Fixed
allow_fopen_url
issue.
- Loading branch information
rwarasaurus
committed
Feb 3, 2013
1 parent
b85dc7e
commit 4abaa7c
Showing
50 changed files
with
466 additions
and
1,219 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<?php | ||
|
||
return array( | ||
'current' => 90 | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
abstract class Migration { | ||
abstract public function up(); | ||
abstract public function down(); | ||
|
||
public function has_table($name) { | ||
$default = Config::get('database.default'); | ||
$db = Config::get('database.connections.' . $default . '.database'); | ||
|
||
$sql = 'SELECT table_name FROM information_schema.tables | ||
WHERE table_schema = ? AND table_name = ?'; | ||
$result = DB::query($sql, array($db, $name)); | ||
|
||
return count($result); | ||
} | ||
|
||
public function has_table_column($table, $name) { | ||
$default = Config::get('database.default'); | ||
$db = Config::get('database.connections.' . $default . '.database'); | ||
|
||
$sql = 'SELECT table_name FROM information_schema.columns | ||
WHERE table_schema = ? AND table_name = ? AND column_name = ?'; | ||
$result = DB::query($sql, array($db, $table, $name)); | ||
|
||
return count($result); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
<?php | ||
|
||
class Migrations { | ||
|
||
private $current; | ||
|
||
public function __construct($current) { | ||
$this->current = intval($current); | ||
} | ||
|
||
public function files($reverse = false) { | ||
$iterator = new FilesystemIterator(APP . 'migrations', FilesystemIterator::SKIP_DOTS); | ||
$files = array(); | ||
|
||
foreach($iterator as $file) { | ||
$parts = explode('_', $file->getBasename(EXT)); | ||
$num = array_shift($parts); | ||
|
||
$files[$num] = array( | ||
'path' => $file->getPathname(), | ||
'class' => 'Migration_' . implode('_', $parts) | ||
); | ||
} | ||
|
||
if($reverse) { | ||
krsort($files, SORT_NUMERIC); | ||
} | ||
else { | ||
ksort($files, SORT_NUMERIC); | ||
} | ||
|
||
return $files; | ||
} | ||
|
||
public function up($to = null) { | ||
// sorted migration files | ||
$files = $this->files(); | ||
|
||
if(is_null($to)) $to = end(array_keys($files)); | ||
|
||
// run migrations | ||
foreach($files as $num => $item) { | ||
// upto | ||
if($num > $to) break; | ||
|
||
// starting from | ||
if($num < $this->current) continue; | ||
|
||
// run | ||
require $item['path']; | ||
|
||
$m = new $item['class']; | ||
|
||
$m->up(); | ||
} | ||
|
||
return $num; | ||
} | ||
|
||
public function down() { | ||
// reverse sorted migration files | ||
$files = $this->files(true); | ||
|
||
if(is_null($to)) $to = current(array_keys($files)); | ||
|
||
// run migrations | ||
foreach($files as $num => $item) { | ||
// upto | ||
if($num < $to) break; | ||
|
||
// starting from | ||
if($num > $this->current) continue; | ||
|
||
// run | ||
require $item['path']; | ||
|
||
$m = new $item['class']; | ||
|
||
$m->down(); | ||
} | ||
|
||
return $num; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php | ||
|
||
class Migration_add_comment_notifications extends Migration { | ||
|
||
public function up() { | ||
if( ! Query::table('meta')->where('key', '=', 'comment_notifications')->count()) { | ||
Query::table('meta')->insert(array( | ||
'key' => 'comment_notifications', | ||
'value' => 0 | ||
)); | ||
} | ||
} | ||
|
||
public function down() { | ||
Query::table('meta')->where('key', '=', 'comment_notifications')->delete(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php | ||
|
||
class Migration_add_comment_moderation_keys extends Migration { | ||
|
||
public function up() { | ||
if( ! Query::table('meta')->where('key', '=', 'comment_moderation_keys')->count()) { | ||
Query::table('meta')->insert(array( | ||
'key' => 'comment_moderation_keys', | ||
'value' => '' | ||
)); | ||
} | ||
} | ||
|
||
public function down() { | ||
Query::table('meta')->where('key', '=', 'comment_moderation_keys')->delete(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?php | ||
|
||
class Migration_alter_comments_status extends Migration { | ||
|
||
public function up() { | ||
$sql = 'ALTER TABLE `comments` CHANGE `status` `status` enum(\'pending\',\'approved\',\'spam\') NOT NULL AFTER `post`'; | ||
DB::query($sql); | ||
} | ||
|
||
public function down() {} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?php | ||
|
||
class Migration_alter_comments_date extends Migration { | ||
|
||
public function up() { | ||
$sql = 'ALTER TABLE `comments` CHANGE `date` `date` datetime NOT NULL AFTER `status`'; | ||
DB::query($sql); | ||
} | ||
|
||
public function down() {} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
class Migration_create_extend_table extends Migration { | ||
|
||
public function up() { | ||
if( ! $this->has_table('extend')) { | ||
$sql = "CREATE TABLE IF NOT EXISTS `extend` ( | ||
`id` int(6) NOT NULL AUTO_INCREMENT, | ||
`type` enum('post','page') NOT NULL, | ||
`field` enum('text','html','image','file') NOT NULL, | ||
`key` varchar(160) NOT NULL, | ||
`label` varchar(160) NOT NULL, | ||
`attributes` text NOT NULL, | ||
PRIMARY KEY (`id`) | ||
) ENGINE=InnoDB"; | ||
|
||
DB::query($sql); | ||
} | ||
} | ||
|
||
public function down() { | ||
$sql = 'DROP TABLE `extend`'; | ||
DB::query($sql); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
class Migration_create_page_meta_table extends Migration { | ||
|
||
public function up() { | ||
if( ! $this->has_table('page_meta')) { | ||
$sql = "CREATE TABLE IF NOT EXISTS `page_meta` ( | ||
`id` int(6) NOT NULL AUTO_INCREMENT, | ||
`page` int(6) NOT NULL, | ||
`extend` int(6) NOT NULL, | ||
`data` text NOT NULL, | ||
PRIMARY KEY (`id`), | ||
KEY `page` (`page`), | ||
KEY `extend` (`extend`) | ||
) ENGINE=InnoDB"; | ||
|
||
DB::query($sql); | ||
} | ||
} | ||
|
||
public function down() { | ||
$sql = 'DROP TABLE `page_meta`'; | ||
DB::query($sql); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
class Migration_create_post_meta_table extends Migration { | ||
|
||
public function up() { | ||
if( ! $this->has_table('post_meta')) { | ||
$sql = "CREATE TABLE IF NOT EXISTS `post_meta` ( | ||
`id` int(6) NOT NULL AUTO_INCREMENT, | ||
`post` int(6) NOT NULL, | ||
`extend` int(6) NOT NULL, | ||
`data` text NOT NULL, | ||
PRIMARY KEY (`id`), | ||
KEY `item` (`post`), | ||
KEY `extend` (`extend`) | ||
) ENGINE=InnoDB"; | ||
|
||
DB::query($sql); | ||
} | ||
} | ||
|
||
public function down() { | ||
$sql = 'DROP TABLE `post_meta`'; | ||
DB::query($sql); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?php | ||
|
||
class Migration_drop_posts_custom_fields extends Migration { | ||
|
||
public function up() { | ||
if($this->has_table_column('posts', 'custom_fields')) { | ||
$sql = 'ALTER TABLE `posts` DROP `custom_fields`'; | ||
DB::query($sql); | ||
} | ||
} | ||
|
||
public function down() {} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?php | ||
|
||
class Migration_alter_posts_created extends Migration { | ||
|
||
public function up() { | ||
$sql = 'ALTER TABLE `posts` CHANGE `created` `created` datetime NOT NULL AFTER `js`'; | ||
DB::query($sql); | ||
} | ||
|
||
public function down() {} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
|
||
class Migration_add_posts_category extends Migration { | ||
|
||
public function up() { | ||
if( ! $this->has_table_column('posts', 'category')) { | ||
$sql = 'ALTER TABLE `posts` ADD `category` int(6) NOT NULL AFTER `author`'; | ||
DB::query($sql); | ||
} | ||
} | ||
|
||
public function down() { | ||
if($this->has_table_column('posts', 'category')) { | ||
$sql = 'ALTER TABLE `posts` DROP `category`'; | ||
DB::query($sql); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
|
||
class Migration_create_categories_table extends Migration { | ||
|
||
public function up() { | ||
if( ! $this->has_table('categories')) { | ||
$sql = 'CREATE TABLE IF NOT EXISTS `categories` ( | ||
`id` int(6) NOT NULL AUTO_INCREMENT, | ||
`title` varchar(150) NOT NULL, | ||
`slug` varchar(40) NOT NULL, | ||
`description` text NOT NULL, | ||
PRIMARY KEY (`id`) | ||
) ENGINE=InnoDB'; | ||
|
||
DB::query($sql); | ||
} | ||
} | ||
|
||
public function down() { | ||
$sql = 'DROP TABLE `categories`'; | ||
DB::query($sql); | ||
} | ||
|
||
} |
Oops, something went wrong.