Archived
1
0
This repository has been archived on 2020-12-10. You can view files and clone it, but cannot push or open issues or pull requests.
old/application/models/DatabaseModel.php
2018-10-16 18:28:42 +02:00

373 lines
14 KiB
PHP

<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class DatabaseModel extends CI_Model
{
public function __construct()
{
parent::__construct();
$this->createMissingDatbases();
}
public function createMissingDatbases() {
$this->createDatabases();
$this->createTables();
$this->fillBlogDb();
$this->fillMainDb();
$this->fillPortfolioDb();
}
public function createDatabases() {
// $this->db->query('CREATE DATABASE IF NOT EXISTS `blog` DEFAULT CHARACTER SET latin1 COLLATE latin1_swedish_ci');
// $this->db->query('CREATE DATABASE IF NOT EXISTS `kingofdog` DEFAULT CHARACTER SET latin1 COLLATE latin1_swedish_ci');
// $this->db->query('CREATE DATABASE IF NOT EXISTS `portfolio` DEFAULT CHARACTER SET latin1 COLLATE latin1_swedish_ci');
// $this->db->query('CREATE DATABASE IF NOT EXISTS `social_media` DEFAULT CHARACTER SET latin1 COLLATE latin1_swedish_ci');
}
public function createTables()
{
// Calendar Table
$this->db->query('CREATE TABLE IF NOT EXISTS `calendar` (
`id` INT(11) NOT NULL AUTO_INCREMENT,
`title` VARCHAR(300) NOT NULL,
`allDay` TINYINT(1) NOT NULL,
`start` VARCHAR(20) NOT NULL,
`end` VARCHAR(20) NOT NULL,
`url` TEXT NOT NULL,
`overlap` TINYINT(1) NOT NULL,
`color` TEXT NOT NULL,
`textColor` TEXT NOT NULL,
`description` TEXT NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=latin1');
// Feedback Table
$this->db->query('CREATE TABLE IF NOT EXISTS `feedback` (
`ID` INT(11) NOT NULL AUTO_INCREMENT,
`page` VARCHAR(100) DEFAULT NULL,
`message` TEXT,
`datetime` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
`anonymous` TINYINT(1) DEFAULT \'1\',
`userID` INT(11) DEFAULT NULL,
`email` VARCHAR(50) DEFAULT NULL,
PRIMARY KEY (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=latin1');
// Files Table
$this->db->query('CREATE TABLE IF NOT EXISTS `files` (
`ID` INT(11) NOT NULL AUTO_INCREMENT,
`name` VARCHAR(50) NOT NULL,
`original_name` VARCHAR(50) NOT NULL,
`type` VARCHAR(30) NOT NULL,
`size` INT(11) NOT NULL,
`path` VARCHAR(300) NOT NULL,
`uploadDate` DATETIME DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=72 DEFAULT CHARSET=latin1');
// Redirects Table
$this->db->query('CREATE TABLE IF NOT EXISTS `redirects` (
`ID` INT(11) NOT NULL AUTO_INCREMENT,
`date` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
`redirect` TEXT NOT NULL,
`url` TEXT NOT NULL,
`temporary` TINYINT(1) NOT NULL,
`expireDate` DATETIME DEFAULT NULL,
PRIMARY KEY (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=220 DEFAULT CHARSET=latin1');
// User Followers Table
$this->db->query('CREATE TABLE IF NOT EXISTS `user_followers` (
`followedUserID` INT(11) NOT NULL,
`followerUserID` INT(11) NOT NULL,
`followedSince` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=latin1');
// User Posts Table
$this->db->query('CREATE TABLE IF NOT EXISTS `user_posts` (
`ID` INT(11) NOT NULL AUTO_INCREMENT,
`user_id` INT(11) DEFAULT NULL,
`title` VARCHAR(150) NOT NULL,
`content` TEXT,
`date` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
`reply_to` INT(11) DEFAULT NULL,
PRIMARY KEY (`ID`),
UNIQUE KEY `user_posts_ID_uindex` (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=145 DEFAULT CHARSET=latin1');
// User Posts Likes Table
$this->db->query('CREATE TABLE IF NOT EXISTS `user_posts_likes` (
`postID` INT(11) NOT NULL,
`likedUserID` INT(11) NOT NULL,
`likerUserID` INT(11) NOT NULL,
UNIQUE KEY `likerUserID` (`likerUserID`),
UNIQUE KEY `postID` (`postID`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1');
// Users Table
$this->db->query('CREATE TABLE IF NOT EXISTS `users` (
`ID` INT(11) NOT NULL AUTO_INCREMENT,
`original_name` VARCHAR(25) NOT NULL,
`username` VARCHAR(25) NOT NULL,
`displayname` VARCHAR(25) NOT NULL,
`login_method` INT(11) DEFAULT \'0\',
`password` TEXT,
`email` TEXT NOT NULL,
`rank` TEXT NOT NULL,
`profile_picture` TEXT NOT NULL,
`header_image` TEXT,
`social_networks` TEXT,
`is_activated` TINYINT(1) NOT NULL,
`activation_key` VARCHAR(256) DEFAULT NULL,
`showAds` TINYINT(1) NOT NULL DEFAULT \'1\',
`date_created` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
`isCurrentlyOnline` TINYINT(1) DEFAULT \'0\',
`about` TEXT NOT NULL,
`lastLogin` DATETIME NOT NULL,
`language` VARCHAR(10) DEFAULT \'DE\',
`country` VARCHAR(2) DEFAULT NULL,
`gender` VARCHAR(10) DEFAULT NULL,
`receiveEmails` TINYINT(1) NOT NULL DEFAULT \'1\',
`receiveNewsletter` TINYINT(1) NOT NULL DEFAULT \'1\',
`forget_password_key` VARCHAR(256) DEFAULT NULL,
`isDeleted` TINYINT(1) DEFAULT \'0\',
UNIQUE KEY `id` (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=13 DEFAULT CHARSET=latin1');
// Users History Table
$this->db->query('CREATE TABLE IF NOT EXISTS `users_history` (
`changeID` INT(11) NOT NULL AUTO_INCREMENT,
`changeDate` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
`ID` INT(11) NOT NULL,
`username` VARCHAR(25) NOT NULL,
`displayname` VARCHAR(25) NOT NULL,
`email` TEXT NOT NULL,
`rank` INT(11) NOT NULL,
`profile_picture` TEXT NOT NULL,
`header_image` TEXT,
`social_networks` TEXT,
`showAds` TINYINT(1) NOT NULL DEFAULT \'1\',
`about` TEXT NOT NULL,
`language` VARCHAR(10) DEFAULT \'DE\',
`country` VARCHAR(2) DEFAULT NULL,
`gender` VARCHAR(10) DEFAULT NULL,
`receiveEmails` TINYINT(1) NOT NULL DEFAULT \'1\',
`receiveNewsletter` TINYINT(1) NOT NULL DEFAULT \'1\',
UNIQUE KEY `changeID` (`changeID`)
) ENGINE=InnoDB AUTO_INCREMENT=14 DEFAULT CHARSET=latin1');
// Blog Categories Table
$this->db->query('CREATE TABLE IF NOT EXISTS `blog_categories` (
`ID` INT(11) NOT NULL AUTO_INCREMENT,
`name` VARCHAR(25) NOT NULL,
`display_name` VARCHAR(50) NOT NULL,
PRIMARY KEY (`ID`),
UNIQUE KEY `blog_categories_name_display_name_uindex` (`name`,`display_name`)
) ENGINE=InnoDB AUTO_INCREMENT=18 DEFAULT CHARSET=latin1');
// Blog Comments Table
$this->db->query('CREATE TABLE IF NOT EXISTS `blog_comments` (
`ID` INT(11) NOT NULL AUTO_INCREMENT,
`post_id` INT(11) NOT NULL,
`user_id` INT(11) NOT NULL,
`comment` TEXT NOT NULL,
`date_created` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
`like_count` INT(11) NOT NULL,
`reply` TINYINT(1) NOT NULL DEFAULT \'0\',
`replyTo_id` INT(11) DEFAULT NULL,
PRIMARY KEY (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=latin1');
// Blog Content Table
$this->db->query('CREATE TABLE IF NOT EXISTS `blog_content` (
`contentID` INT(11) NOT NULL AUTO_INCREMENT,
`postID` INT(11) NOT NULL,
`contentDate` DATETIME NOT NULL,
`content` MEDIUMTEXT NOT NULL,
`contentAuthorID` INT(11) DEFAULT NULL,
`isNativePost` TINYINT(1) NOT NULL,
`isActive` TINYINT(1) NOT NULL,
`versionMessage` VARCHAR(300) NOT NULL,
`language` VARCHAR(10) DEFAULT NULL,
PRIMARY KEY (`contentID`)
) ENGINE=InnoDB AUTO_INCREMENT=42 DEFAULT CHARSET=latin1');
// Blog Posts Table
$this->db->query('CREATE TABLE IF NOT EXISTS `blog_posts` (
`postID` INT(11) NOT NULL AUTO_INCREMENT,
`postUrl` VARCHAR(300) NOT NULL,
`postTitle` VARCHAR(255) DEFAULT NULL,
`postDesc` TEXT,
`postPublishDate` DATETIME DEFAULT NULL,
`postLastEdit` DATETIME DEFAULT NULL,
`postAuthorID` INT(11) DEFAULT NULL,
`postImage` TEXT NOT NULL,
`postState` VARCHAR(50) NOT NULL,
`postViews` INT(11) NOT NULL DEFAULT \'0\',
`postCategoryID` INT(11) NOT NULL,
`postIsDeleted` TINYINT(1) NOT NULL DEFAULT \'0\',
`postDeletedDate` DATETIME DEFAULT NULL,
PRIMARY KEY (`postID`)
) ENGINE=InnoDB AUTO_INCREMENT=43 DEFAULT CHARSET=latin1');
// Blog Post Likes Table
$this->db->query('CREATE TABLE IF NOT EXISTS `blog_post_likes` (
`post_id` int(11) NOT NULL,
`user_id` int(11) NOT NULL,
PRIMARY KEY (`post_id`,`user_id`),
KEY `fk_post_likes_user` (`user_id`),
CONSTRAINT `fk_post_likes_post` FOREIGN KEY (`post_id`) REFERENCES `blog_posts` (`postID`),
CONSTRAINT `fk_post_likes_user` FOREIGN KEY (`user_id`) REFERENCES `users` (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1');
// Blog Post Tags Table
$this->db->query('CREATE TABLE IF NOT EXISTS `blog_post_tags` (
`post_id` INT(11) NOT NULL,
`tag_id` INT(11) NOT NULL,
PRIMARY KEY (`post_id`,`tag_id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1');
// Blog States Table
$this->db->query('CREATE TABLE IF NOT EXISTS `blog_states` (
`ID` INT(11) NOT NULL AUTO_INCREMENT,
`name` VARCHAR(15) NOT NULL,
`display_name` VARCHAR(15) NOT NULL,
PRIMARY KEY (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=latin1');
// Blog Tags Table
$this->db->query('CREATE TABLE IF NOT EXISTS `blog_tags` (
`ID` INT(11) NOT NULL AUTO_INCREMENT,
`name` VARCHAR(25) NOT NULL,
`display_name` VARCHAR(50) NOT NULL,
PRIMARY KEY (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=49 DEFAULT CHARSET=latin1');
// Blog Translations Table
$this->db->query('CREATE TABLE IF NOT EXISTS `blog_translations` (
`postID` INT(11) DEFAULT NULL,
`language` VARCHAR(10) DEFAULT \'en\',
`postTitle` VARCHAR(255) DEFAULT NULL,
`postDesc` TEXT,
UNIQUE KEY `blog_translations_language_uindex` (`language`),
UNIQUE KEY `blog_translations_postID_uindex` (`postID`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1');
// Collections Table
$this->db->query('CREATE TABLE IF NOT EXISTS `collections` (
`ID` INT(11) NOT NULL AUTO_INCREMENT,
`collection` TEXT NOT NULL,
`displayname` TEXT NOT NULL,
`displaynameEnglish` TEXT NOT NULL,
`displaynameFrench` TEXT NOT NULL,
PRIMARY KEY (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=17 DEFAULT CHARSET=latin1');
// Portfolio Table
$this->db->query('CREATE TABLE IF NOT EXISTS `portfolio` (
`ID` INT(11) NOT NULL AUTO_INCREMENT,
`name` VARCHAR(255) NOT NULL,
`datetime` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
`source` TEXT NOT NULL,
`isDownloadable` TINYINT(1) NOT NULL DEFAULT \'0\',
`isOpenSource` TINYINT(1) NOT NULL DEFAULT \'0\',
`title` TEXT NOT NULL,
`titleEnglish` TEXT NOT NULL,
`titleFrench` TEXT NOT NULL,
`headline` TEXT NOT NULL,
`headlineEnglish` TEXT NOT NULL,
`headlineFrench` TEXT NOT NULL,
`description` TEXT NOT NULL,
`descriptionEnglish` TEXT NOT NULL,
`descriptionFrench` TEXT NOT NULL,
PRIMARY KEY (`ID`),
UNIQUE KEY `name` (`name`)
) ENGINE=InnoDB AUTO_INCREMENT=38 DEFAULT CHARSET=latin1');
// Project Categories Table
$this->db->query('CREATE TABLE IF NOT EXISTS `project_categories` (
`projectID` INT(11) NOT NULL,
`categoryID` INT(11) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1');
// Social Posts Table
$this->db->query('CREATE TABLE IF NOT EXISTS `social_posts` (
`post_id` INT(11) NOT NULL AUTO_INCREMENT,
`post_plattform` VARCHAR(20) NOT NULL,
`post_content` TEXT NOT NULL,
`post_url` VARCHAR(75) NOT NULL,
`post_author` VARCHAR(20) NOT NULL,
`post_author_url` TEXT NOT NULL,
`post_date` INT(11) NOT NULL,
`post_img_source` TEXT,
`post_original_id` BIGINT(20) NOT NULL,
PRIMARY KEY (`post_id`),
UNIQUE KEY `post_url` (`post_url`)
) ENGINE=InnoDB AUTO_INCREMENT=5474 DEFAULT CHARSET=latin1');
}
public function fillBlogDb() {
if($this->db->query('SELECT COUNT(*) count FROM blog_categories')->result_array()[0]['count'] == 0) {
$this->db->query("INSERT INTO `blog_categories` (`ID`, `name`, `display_name`) VALUES
(1, 'design', 'Design'),
(2, 'development', 'Entwicklung & Programmierung'),
(3, 'internet', 'Internet'),
(4, 'minepoint', 'MinePoint'),
(5, 'social_media', 'Soziale Medien'),
(6, 'technic', 'Technik'),
(7, 'youtube', 'YouTube')");
}
if($this->db->query('SELECT COUNT(*) count FROM blog_states')->result_array()[0]['count'] == 0) {
$this->db->query("INSERT INTO `blog_states` (`ID`, `name`, `display_name`) VALUES
(1, 'published', 'Veröffentlicht'),
(2, 'draft', 'Entwurf'),
(3, 'pending', 'Geplant'),
(4, 'trashbin', 'Im Papierkorb')");
}
if($this->db->query('SELECT COUNT(*) count FROM blog_tags')->result_array()[0]['count'] == 0) {
$this->db->query("INSERT INTO `blog_tags` (`ID`, `name`, `display_name`) VALUES
(1, 'youtube', 'YouTube'),
(2, 'twitter', 'Twitter'),
(3, 'smartphones', 'Smartphones'),
(4, 'coding', 'Programmieren'),
(5, 'development', 'Entwicklung'),
(6, 'design', 'Design'),
(7, 'adobe', 'Adobe'),
(8, '3d', '3D'),
(9, 'ux', 'User Experience'),
(10, 'ui', 'User Interface'),
(11, 'design-thinking', 'Thinking on Design'),
(12, 'games', 'Spiele'),
(13, 'hardware', 'Hardware'),
(14, 'software', 'Software'),
(15, 'photography', 'Fotografie'),
(16, 'videos', 'Videos & Filmen'),
(17, 'learning', 'Lernen'),
(28, '', ''),
(29, 'test', 'test'),
(30, 'kacke', 'kacke'),
(31, 'asdfla', 'asdfla'),
(32, 'admin', 'Admin'),
(33, 'tset', 'tset'),
(34, 'programmiersprachen', 'Programmiersprachen'),
(35, 'sprachen', 'Sprachen'),
(36, 'serie', 'Serie'),
(37, 'kanal', 'Kanal'),
(38, 'neu', 'Neu'),
(39, 'kingofdog', 'KingOfDog'),
(40, 'entwicklung', 'Entwicklung'),
(41, 'programmierung', 'Programmierung'),
(42, 'webseite', 'Webseite'),
(43, 'posts', 'Posts'),
(44, 'post', 'Post'),
(45, 'system', 'System'),
(46, 'nutzer', 'Nutzer'),
(47, 'user', 'User'),
(48, 'php', 'PHP')");
}
}
public function fillMainDb() {
if($this->db->query('SELECT COUNT(*) count FROM redirects')->result_array()[0]['count'] == 0) {
$this->db->query("INSERT INTO `redirects` (`ID`, `date`, `redirect`, `url`, `temporary`, `expireDate`) VALUES
(1, '2016-10-15 18:09:51', 'yt', 'http://youtube.com/KingOfDog', 0, '0000-00-00 00:00:00'),
(2, '2016-10-15 18:10:13', 'youtube', 'http://youtube.com/KingOfDog', 0, '0000-00-00 00:00:00'),
(3, '2016-10-15 18:10:27', 'tw', 'http://twitter.com/KingOfDogTV', 0, '0000-00-00 00:00:00'),
(4, '2016-10-15 18:10:37', 'twitter', 'http://twitter.com/KingOfDogTV', 0, '0000-00-00 00:00:00')");
}
}
public function fillPortfolioDb() {
if($this->db->query('SELECT COUNT(*) count FROM projects_categories')->result_array()[0]['count'] == 0) {
$this->db->query("INSERT INTO `projects_categories` (`ID`, `collection`, `displayname`, `displaynameEnglish`, `displaynameFrench`) VALUES
(1, 'banner', 'Banner', 'Banner', 'Bannière'),
(2, 'fotografie', 'Fotografie', 'Photography', 'Photographie'),
(3, 'minecraft', 'Minecraft', 'Minecraft', 'Minecraft'),
(4, 'websites', 'Webseiten', 'Websites', 'Sites'),
(5, 'logo', 'Logo', 'Logo', 'Logo'),
(6, 'development', 'Programmierung', 'Development', ''),
(7, 'games', 'Spiele', 'Games', ''),
(8, 'design', 'Design', 'Design', 'Design')");
}
}
}