Skip to content
This repository has been archived by the owner on May 19, 2020. It is now read-only.

Commit

Permalink
man, fuck one click upgrade. Fixed allow_fopen_url issue.
Browse files Browse the repository at this point in the history
  • Loading branch information
rwarasaurus committed Feb 3, 2013
1 parent b85dc7e commit 4abaa7c
Show file tree
Hide file tree
Showing 50 changed files with 466 additions and 1,219 deletions.
5 changes: 5 additions & 0 deletions anchor/config/migrations.php
@@ -0,0 +1,5 @@
<?php

return array(
'current' => 90
);
28 changes: 28 additions & 0 deletions anchor/libraries/migration.php
@@ -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);
}
}
85 changes: 85 additions & 0 deletions anchor/libraries/migrations.php
@@ -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;
}

}
24 changes: 23 additions & 1 deletion anchor/libraries/update.php
Expand Up @@ -45,7 +45,29 @@ public static function renew() {
}

public static function touch() {
return file_get_contents('http://anchorcms.com/version');
$url = 'http://anchorcms.com/version';

if(in_array(ini_get('allow_url_fopen'), array('true', '1', 'On'))) {
$result = file_get_contents($url);
}
else if(function_exists('curl_init')) {
$session = curl_init();

curl_setopt_array($session, array(
CURLOPT_URL => $url,
CURLOPT_HEADER => false,
CURLOPT_RETURNTRANSFER => true
));

$result = curl_exec($session);

curl_close($session);
}
else {
$result = false;
}

return $result;
}

}
18 changes: 18 additions & 0 deletions anchor/migrations/10_add_comment_notifications.php
@@ -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();
}

}
18 changes: 18 additions & 0 deletions anchor/migrations/11_add_comment_moderation_keys.php
@@ -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();
}

}
12 changes: 12 additions & 0 deletions anchor/migrations/20_alter_comments_status.php
@@ -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() {}

}
12 changes: 12 additions & 0 deletions anchor/migrations/21_alter_comments_date.php
@@ -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() {}

}
26 changes: 26 additions & 0 deletions anchor/migrations/30_create_extend_table.php
@@ -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);
}

}
26 changes: 26 additions & 0 deletions anchor/migrations/40_create_page_meta_table.php
@@ -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);
}

}
26 changes: 26 additions & 0 deletions anchor/migrations/50_create_post_meta_table.php
@@ -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);
}

}
14 changes: 14 additions & 0 deletions anchor/migrations/60_drop_posts_custom_fields.php
@@ -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() {}

}
12 changes: 12 additions & 0 deletions anchor/migrations/61_alter_posts_created.php
@@ -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() {}

}
19 changes: 19 additions & 0 deletions anchor/migrations/62_add_posts_category.php
@@ -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);
}
}

}
24 changes: 24 additions & 0 deletions anchor/migrations/70_create_categories_table.php
@@ -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);
}

}

0 comments on commit 4abaa7c

Please sign in to comment.