public function up()
 {
     $table = Base::table('pages');
     $table2 = Base::table('posts');
     if ($this->has_table_column($table, 'content')) {
         $sql = 'ALTER TABLE `' . $table . '` ';
         $sql .= 'CHANGE `content` `markdown` TEXT';
         DB::ask($sql);
     }
     if (!$this->has_table_column($table, 'html') && $this->has_table_column($table, 'markdown')) {
         $sql = 'ALTER TABLE `' . $table . '` ';
         $sql .= 'ADD `html` TEXT NOT NULL AFTER `markdown`';
         DB::ask($sql);
         $pages = Page::sort('menu_order', 'desc')->get();
         foreach ($pages as $page) {
             Page::update($page->id, array('html' => parse($page->markdown)));
         }
     }
     if (!$this->has_table_column($table2, 'markdown') && $this->has_table_column($table2, 'html')) {
         $sql = 'ALTER TABLE `' . $table2 . '` ';
         $sql .= 'ADD `markdown` TEXT NOT NULL AFTER `description`';
         DB::ask($sql);
         $migrate_data_sql = 'update `' . $table2 . '` set `markdown` = `html`, `html` = "";';
         DB::ask($migrate_data_sql);
         $posts = Post::sort('created', 'desc')->get();
         foreach ($posts as $post) {
             Post::update($post->id, array('html' => parse($post->markdown)));
         }
     }
 }
 public function down()
 {
     $posts = Base::table('posts');
     if ($this->has_table($posts)) {
         if ($this->has_table_column($posts, 'updated')) {
             $sql = 'ALTER TABLE `' . $posts . '` ';
             $sql .= 'DROP COLUMN `updated`';
             DB::ask($sql);
         }
     }
     $pages = Base::table('pages');
     if ($this->has_table($pages)) {
         if ($this->has_table_column($pages, 'updated')) {
             $sql = 'ALTER TABLE `' . $pages . '` ';
             $sql .= 'DROP COLUMN `updated`';
             DB::ask($sql);
         }
     }
     $users = Base::table('users');
     if ($this->has_table($users)) {
         if ($this->has_table_column($users, 'updated')) {
             $sql = 'ALTER TABLE `' . $users . '` ';
             $sql .= 'DROP COLUMN `updated`';
             DB::ask($sql);
         }
     }
 }
Beispiel #3
0
 public static function search($term, $page = 1, $per_page = 10)
 {
     $query = static::left_join(Base::table('users'), Base::table('users.id'), '=', Base::table('posts.author'))->where(Base::table('posts.status'), '=', 'published')->where(Base::table('posts.title'), 'like', '%' . $term . '%');
     $total = $query->count();
     $posts = $query->take($per_page)->skip(--$page * $per_page)->get(array(Base::table('posts.*'), Base::table('users.id as author_id'), Base::table('users.bio as author_bio'), Base::table('users.real_name as author_name')));
     return array($total, $posts);
 }
 public function up()
 {
     $table = Base::table('comments');
     if ($this->has_table($table)) {
         $sql = 'ALTER TABLE `' . $table . '` CHANGE `date` `date` datetime NOT NULL AFTER `status`';
         DB::ask($sql);
     }
 }
 public function up()
 {
     $table = Base::table('posts');
     if ($this->has_table_column($table, 'created')) {
         $sql = 'ALTER TABLE `' . $table . '` CHANGE `created` `created` datetime NOT NULL AFTER `js`';
         DB::ask($sql);
     }
 }
 public function up()
 {
     $table = Base::table('posts');
     if (!$this->has_table_column($table, 'category')) {
         $sql = 'ALTER TABLE `' . $table . '` ADD `category` int(6) NOT NULL AFTER `author`';
         DB::query($sql);
     }
 }
 public function down()
 {
     $table = Base::table('extend');
     if ($this->has_table_column($table, 'type')) {
         $sql = 'ALTER TABLE `' . $table . '` MODIFY COLUMN `type` enum("post", "page") NOT NULL';
         DB::ask($sql);
     }
 }
 public function up()
 {
     $table = Base::table('users');
     if ($this->has_table_column($table, 'password')) {
         $sql = 'ALTER TABLE `' . $table . '` CHANGE `password` `password` text NOT NULL AFTER `username`';
         DB::ask($sql);
     }
 }
 public function up()
 {
     $table = Base::table('category_meta');
     if (!$this->has_table($table)) {
         $sql = "CREATE TABLE IF NOT EXISTS `" . $table . "` (\n                `id` int(6) NOT NULL AUTO_INCREMENT,\n                `category` int(6) NOT NULL,\n                `extend` int(6) NOT NULL,\n                `data` text NOT NULL,\n                PRIMARY KEY (`id`),\n                KEY `item` (`category`),\n                KEY `extend` (`extend`)\n            ) ENGINE=InnoDB";
         DB::ask($sql);
     }
 }
 public function up()
 {
     $table = Base::table('extend');
     if (!$this->has_table($table)) {
         $sql = "CREATE TABLE IF NOT EXISTS `' . {$table} . '` (\n\t\t\t\t`id` int(6) NOT NULL AUTO_INCREMENT,\n\t\t\t\t`type` enum('post','page') NOT NULL,\n\t\t\t\t`field` enum('text','html','image','file') NOT NULL,\n\t\t\t\t`key` varchar(160) NOT NULL,\n\t\t\t\t`label` varchar(160) NOT NULL,\n\t\t\t\t`attributes` text NOT NULL,\n\t\t\t\tPRIMARY KEY (`id`)\n\t\t\t) ENGINE=InnoDB";
         DB::ask($sql);
     }
 }
 public function up()
 {
     $table = Base::table('sessions');
     if ($this->has_table_column($table, 'ip')) {
         $sql = 'ALTER TABLE `' . $table . '` DROP `ip`';
         DB::ask($sql);
     }
 }
 public function up()
 {
     $table = Base::table('pages');
     if (!$this->has_table_column($table, 'parent')) {
         $sql = 'ALTER TABLE `' . $table . '` ADD `parent` int(6) NOT NULL AFTER `id`';
         DB::ask($sql);
     }
 }
 public function up()
 {
     $table = Base::table('pages');
     if (!$this->has_table_column($table, 'show_in_menu')) {
         $sql = 'ALTER TABLE `' . $table . '` ADD `show_in_menu` tinyint(1) NOT NULL';
         DB::ask($sql);
     }
 }
 public function up()
 {
     $table = Base::table('pages');
     if (!$this->has_table_column($table, 'menu_order')) {
         $sql = 'ALTER TABLE `' . $table . '` ADD `menu_order` int(4) NOT NULL DEFAULT 0';
         DB::ask($sql);
     }
 }
 public function up()
 {
     $table = Base::table('comments');
     if ($this->has_table($table)) {
         $sql = 'ALTER TABLE `' . $table . '` CHANGE `status` `status` enum(\'pending\',\'approved\',\'spam\') NOT NULL AFTER `post`';
         DB::ask($sql);
     }
 }
 public function up()
 {
     $table = Base::table('post_meta');
     if ($this->has_table_column($table, 'custom_fields')) {
         $sql = 'ALTER TABLE `' . $table . '` DROP `custom_fields`';
         DB::ask($sql);
     }
 }
 public function down()
 {
     $table = Base::table('posts');
     if ($this->has_table_column($table, 'html')) {
         $sql = 'ALTER TABLE `' . $table . '` MODIFY COLUMN `html` TEXT NOT NULL';
         DB::ask($sql);
     }
 }
 public function up()
 {
     $table = Base::table('sessions');
     if ($this->has_table_column($table, 'date')) {
         $sql = 'ALTER TABLE `' . $table . '` CHANGE `date` `expire` int(10) NOT NULL AFTER `id`';
         DB::ask($sql);
     }
 }
 public function up()
 {
     $table = Base::table('page_meta');
     if (!$this->has_table($table)) {
         $sql = "CREATE TABLE IF NOT EXISTS `' . {$table} . '` (\n\t\t\t\t`id` int(6) NOT NULL AUTO_INCREMENT,\n\t\t\t\t`page` int(6) NOT NULL,\n\t\t\t\t`extend` int(6) NOT NULL,\n\t\t\t\t`data` text NOT NULL,\n\t\t\t\tPRIMARY KEY (`id`),\n\t\t\t\tKEY `page` (`page`),\n\t\t\t\tKEY `extend` (`extend`)\n\t\t\t) ENGINE=InnoDB";
         DB::ask($sql);
     }
 }
 public function up()
 {
     $table = Base::table('meta');
     if ($this->has_table($table)) {
         if (!Query::table($table)->where('key', '=', 'comment_notifications')->count()) {
             Query::table($table)->insert(array('key' => 'comment_notifications', 'value' => 0));
         }
     }
 }
 public function up()
 {
     $table = Base::table('categories');
     if ($this->has_table($table)) {
         if (!Query::table($table)->count()) {
             Query::table($table)->insert(array('title' => 'Uncategorised', 'slug' => 'uncategorised', 'description' => 'Ain\'t no category here.'));
         }
     }
 }
 public function up()
 {
     $table = Base::table('pages');
     if ($this->has_table_column($table, 'menu_order')) {
         $sql = 'ALTER TABLE `' . $table . '`;';
         $sql .= 'ALTER COLUMN `menu_order` SET DEFAULT 0';
         DB::ask($sql);
     }
 }
 public function up()
 {
     $table = Base::table('meta');
     if ($this->has_table($table)) {
         if (!Query::table($table)->where('key', '=', 'dashboard_page')->count()) {
             Query::table($table)->insert(array('key' => 'dashboard_page', 'value' => 'panel'));
         } else {
             Query::table($table)->where('key', '=', 'dashboard_page')->update(array('value' => 'panel'));
         }
     }
 }
 public function up()
 {
     $table = Base::table('meta');
     if ($this->has_table($table)) {
         if (!Query::table($table)->where('key', '=', 'show_all_posts')->count()) {
             Query::table($table)->insert(array('key' => 'show_all_posts', 'value' => 0));
         } else {
             Query::table($table)->where('key', '=', 'show_all_posts')->update(array('value' => 0));
         }
     }
 }
 public function up()
 {
     $table = Base::table('user_meta');
     if (!$this->has_table($table)) {
         $sql = "CREATE TABLE IF NOT EXISTS `" . $table . "` (\n\t\t\t\t`id` int(6) NOT NULL AUTO_INCREMENT,\n\t\t\t\t`user` int(6) NOT NULL,\n\t\t\t\t`extend` int(6) NOT NULL,\n\t\t\t\t`data` text NOT NULL,\n\t\t\t\tPRIMARY KEY (`id`),\n\t\t\t\tKEY `item` (`user`),\n\t\t\t\tKEY `extend` (`extend`)\n\t\t\t) ENGINE=InnoDB";
         DB::ask($sql);
     }
     $table2 = Base::table('extend');
     if ($this->has_table($table2)) {
         $sql2 = "ALTER TABLE `" . $table2 . "` CHANGE `type` `type` ENUM('post','page','category','user') NOT NULL";
         DB::ask($sql2);
     }
 }
Beispiel #26
0
 public static function renew()
 {
     $version = static::touch();
     $today = date('Y-m-d H:i:s');
     $table = Base::table('meta');
     Query::table($table)->where('key', '=', 'last_update_check')->update(array('value' => $today));
     Query::table($table)->where('key', '=', 'update_version')->update(array('value' => $version));
     // reload database metadata
     foreach (Query::table($table)->get() as $item) {
         $meta[$item->key] = $item->value;
     }
     Config::set('meta', $meta);
 }
    public function up()
    {
        $table = Base::table('categories');
        if (!$this->has_table($table)) {
            $sql = 'CREATE TABLE IF NOT EXISTS `' . $table . '` (
				`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);
        }
    }
Beispiel #28
0
 public static function search($term, $page = 1, $per_page = 10)
 {
     $query = static::left_join(Base::table('users'), Base::table('users.id'), '=', Base::table('posts.author'))->where(Base::table('posts.status'), '=', 'published')->where(Base::table('posts.title'), 'like', '%' . $term . '%')->or_where(Base::table('posts.html'), 'like', '%' . $term . '%');
     $total = $query->count();
     $posts = $query->take($per_page)->skip(--$page * $per_page)->get(array(Base::table('posts.*'), Base::table('users.id as author_id'), Base::table('users.bio as author_bio'), Base::table('users.real_name as author_name')));
     foreach ($posts as $key => $post) {
         if ($post->data['status'] !== 'published') {
             unset($posts[$key]);
         }
     }
     if (count($posts) < 1) {
         $total = 0;
     }
     return array($total, $posts);
 }
Beispiel #29
0
 public static function search($term, $pageNum = 1, $per_page = 10)
 {
     $query = static::where(Base::table('pages.status'), '=', 'published')->where(Base::table('pages.name'), 'like', '%' . $term . '%');
     //->or_where(Base::table('pages.content'), 'like', '%' . $term . '%'); // This could cause problems?
     $total = $query->count();
     $pages = $query->take($per_page)->skip(--$pageNum * $per_page)->get(array(Base::table('pages.*')));
     foreach ($pages as $key => $page) {
         if ($page->data['status'] !== 'published') {
             unset($pages[$key]);
         }
     }
     if (count($pages) < 1) {
         $total = 0;
     }
     return array($total, $pages);
 }
Beispiel #30
0
 public static function migrations()
 {
     $current = Config::meta('current_migration');
     $migrate_to = Config::migrations('current');
     $migrations = new Migrations($current);
     $table = Base::table('meta');
     if (is_null($current)) {
         $number = $migrations->up($migrate_to);
         Query::table($table)->insert(array('key' => 'current_migration', 'value' => $number));
     } else {
         if ($current < $migrate_to) {
             $number = $migrations->up($migrate_to);
             Query::table($table)->where('key', '=', 'current_migration')->update(array('value' => $number));
         }
     }
 }