Add base schema population

This commit is contained in:
Ivan Diaz 2020-01-22 14:26:07 -03:00
parent 059a6325e9
commit 71a1d434ef
8 changed files with 510 additions and 3 deletions

View File

@ -4,7 +4,7 @@
"respect/validation": "^1.1",
"phpmailer/phpmailer": "^5.2",
"google/recaptcha": "~1.1",
"gabordemooij/redbean": "^4.3",
"gabordemooij/redbean": "^5.4",
"ifsnop/mysqldump-php": "2.*",
"ezyang/htmlpurifier": "^4.8",
"codeguy/upload": "^1.3",

View File

@ -1,4 +1,5 @@
<?php
use RedBeanPHP\Facade as RedBean;
use Respect\Validation\Validator as DataValidator;
DataValidator::with('CustomValidations', true);
@ -52,6 +53,7 @@ class InitSettingsController extends Controller {
public function handler() {
if (Setting::isTableEmpty()) {
RedBean::exec(file_get_contents('data/db_schema.sql'));
$this->storeGlobalSettings();
$this->storeMailTemplates();
$this->storeLanguages();

473
server/data/db_schema.sql Normal file
View File

@ -0,0 +1,473 @@
-- MySQL dump 10.13 Distrib 5.6.46, for Linux (x86_64)
-- ------------------------------------------------------
-- Server version 5.6.46
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;
/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
/*!40103 SET TIME_ZONE='+00:00' */;
/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;
--
-- Table structure for table `apikey`
--
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE IF NOT EXISTS `apikey` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`type` varchar(191) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`name` varchar(191) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`token` varchar(191) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Table structure for table `article`
--
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE IF NOT EXISTS `article` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`title` varchar(191) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`content` varchar(191) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`last_edited` double DEFAULT NULL,
`position` tinyint(1) unsigned DEFAULT NULL,
`topic_id` int(11) unsigned DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `index_foreignkey_article_topic` (`topic_id`),
CONSTRAINT `c_fk_article_topic_id` FOREIGN KEY (`topic_id`) REFERENCES `topic` (`id`) ON DELETE SET NULL ON UPDATE SET NULL
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Table structure for table `ban`
--
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE IF NOT EXISTS `ban` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`email` varchar(191) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Table structure for table `customfield`
--
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE IF NOT EXISTS `customfield` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`name` varchar(191) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`description` varchar(191) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`type` varchar(191) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Table structure for table `customfieldoption`
--
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE IF NOT EXISTS `customfieldoption` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`name` varchar(191) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`customfield_id` int(11) unsigned DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `index_foreignkey_customfieldoption_customfield` (`customfield_id`),
CONSTRAINT `c_fk_customfieldoption_customfield_id` FOREIGN KEY (`customfield_id`) REFERENCES `customfield` (`id`) ON DELETE SET NULL ON UPDATE SET NULL
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Table structure for table `customfieldvalue`
--
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE IF NOT EXISTS `customfieldvalue` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`value` varchar(191) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`user_id` int(11) unsigned DEFAULT NULL,
`customfield_id` int(11) unsigned DEFAULT NULL,
`customfieldoption_id` int(11) unsigned DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `index_foreignkey_customfieldvalue_user` (`user_id`),
KEY `index_foreignkey_customfieldvalue_customfield` (`customfield_id`),
KEY `index_foreignkey_customfieldvalue_customfieldoption` (`customfieldoption_id`),
CONSTRAINT `c_fk_customfieldvalue_customfield_id` FOREIGN KEY (`customfield_id`) REFERENCES `customfield` (`id`) ON DELETE SET NULL ON UPDATE SET NULL,
CONSTRAINT `c_fk_customfieldvalue_customfieldoption_id` FOREIGN KEY (`customfieldoption_id`) REFERENCES `customfieldoption` (`id`) ON DELETE SET NULL ON UPDATE SET NULL,
CONSTRAINT `c_fk_customfieldvalue_user_id` FOREIGN KEY (`user_id`) REFERENCES `user` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Table structure for table `customresponse`
--
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE IF NOT EXISTS `customresponse` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`name` varchar(191) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`language` varchar(191) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`content` varchar(191) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Table structure for table `department`
--
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE IF NOT EXISTS `department` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`owners` int(11) unsigned DEFAULT NULL,
`name` varchar(191) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`private` int(11) unsigned DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Table structure for table `department_staff`
--
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE IF NOT EXISTS `department_staff` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`department_id` int(11) unsigned DEFAULT NULL,
`staff_id` int(11) unsigned DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `UQ_f2a19cacc73eb380315c104650ebc8c42d1b75a0` (`department_id`,`staff_id`),
KEY `index_foreignkey_department_staff_department` (`department_id`),
KEY `index_foreignkey_department_staff_staff` (`staff_id`),
CONSTRAINT `c_fk_department_staff_department_id` FOREIGN KEY (`department_id`) REFERENCES `department` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT `c_fk_department_staff_staff_id` FOREIGN KEY (`staff_id`) REFERENCES `staff` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Table structure for table `language`
--
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE IF NOT EXISTS `language` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`code` varchar(191) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`allowed` int(11) unsigned DEFAULT NULL,
`supported` tinyint(1) unsigned DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Table structure for table `log`
--
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE IF NOT EXISTS `log` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`type` varchar(191) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`to` varchar(191) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`date` double DEFAULT NULL,
`author_name` varchar(191) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`author_staff_id` int(11) unsigned DEFAULT NULL,
`author_user_id` int(11) unsigned DEFAULT NULL,
`author_staff` tinyint(1) unsigned DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `index_foreignkey_log_author_staff` (`author_staff_id`),
KEY `index_foreignkey_log_author_user` (`author_user_id`),
CONSTRAINT `c_fk_log_author_staff_id` FOREIGN KEY (`author_staff_id`) REFERENCES `staff` (`id`) ON DELETE SET NULL ON UPDATE SET NULL,
CONSTRAINT `c_fk_log_author_user_id` FOREIGN KEY (`author_user_id`) REFERENCES `user` (`id`) ON DELETE SET NULL ON UPDATE SET NULL
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Table structure for table `mailtemplate`
--
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE IF NOT EXISTS `mailtemplate` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`template` varchar(191) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`subject` varchar(191) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`language` varchar(191) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`text1` varchar(191) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`text2` varchar(191) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`text3` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Table structure for table `recoverpassword`
--
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE IF NOT EXISTS `recoverpassword` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`email` varchar(191) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`token` varchar(191) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`staff` tinyint(1) unsigned DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Table structure for table `sessioncookie`
--
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE IF NOT EXISTS `sessioncookie` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`token` varchar(191) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`ip` varchar(191) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`creation_date` double DEFAULT NULL,
`expiration_date` double DEFAULT NULL,
`user_id` int(11) unsigned DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `index_foreignkey_sessioncookie_user` (`user_id`),
CONSTRAINT `c_fk_sessioncookie_user_id` FOREIGN KEY (`user_id`) REFERENCES `user` (`id`) ON DELETE SET NULL ON UPDATE SET NULL
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Table structure for table `setting`
--
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE IF NOT EXISTS `setting` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`name` varchar(191) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`value` varchar(191) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Table structure for table `staff`
--
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE IF NOT EXISTS `staff` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`level` int(11) unsigned DEFAULT NULL,
`send_email_on_new_ticket` int(11) unsigned DEFAULT NULL,
`name` varchar(191) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`email` varchar(191) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`password` varchar(191) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`profile_pic` varchar(191) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`verification_token` tinyint(1) unsigned DEFAULT NULL,
`disabled` tinyint(1) unsigned DEFAULT NULL,
`last_login` double DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Table structure for table `staff_ticket`
--
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE IF NOT EXISTS `staff_ticket` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`ticket_id` int(11) unsigned DEFAULT NULL,
`staff_id` int(11) unsigned DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `UQ_8a53d6ad25611e7060ab030785c3c0cef48bc533` (`staff_id`,`ticket_id`),
KEY `index_foreignkey_staff_ticket_ticket` (`ticket_id`),
KEY `index_foreignkey_staff_ticket_staff` (`staff_id`),
CONSTRAINT `c_fk_staff_ticket_staff_id` FOREIGN KEY (`staff_id`) REFERENCES `staff` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT `c_fk_staff_ticket_ticket_id` FOREIGN KEY (`ticket_id`) REFERENCES `ticket` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Table structure for table `tag`
--
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE IF NOT EXISTS `tag` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`name` varchar(191) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`color` varchar(191) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Table structure for table `tag_ticket`
--
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE IF NOT EXISTS `tag_ticket` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`tag_id` int(11) unsigned DEFAULT NULL,
`ticket_id` int(11) unsigned DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `UQ_79dc4901a5620abff6d65219e6aef86fe9ab63bc` (`tag_id`,`ticket_id`),
KEY `index_foreignkey_tag_ticket_tag` (`tag_id`),
KEY `index_foreignkey_tag_ticket_ticket` (`ticket_id`),
CONSTRAINT `c_fk_tag_ticket_tag_id` FOREIGN KEY (`tag_id`) REFERENCES `tag` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT `c_fk_tag_ticket_ticket_id` FOREIGN KEY (`ticket_id`) REFERENCES `ticket` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Table structure for table `ticket`
--
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE IF NOT EXISTS `ticket` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`ticket_number` int(11) unsigned DEFAULT NULL,
`unread` tinyint(1) unsigned DEFAULT NULL,
`priority` varchar(191) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`unread_staff` tinyint(1) unsigned DEFAULT NULL,
`title` varchar(191) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`content` text COLLATE utf8mb4_unicode_ci,
`language` varchar(191) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`file` varchar(191) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`date` double DEFAULT NULL,
`closed` tinyint(1) unsigned DEFAULT NULL,
`author_email` varchar(191) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`author_name` varchar(191) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`department_id` int(11) unsigned DEFAULT NULL,
`author` tinyint(1) unsigned DEFAULT NULL,
`author_id` int(11) unsigned DEFAULT NULL,
`author_staff` tinyint(1) unsigned DEFAULT NULL,
`author_staff_id` int(11) unsigned DEFAULT NULL,
`owner_id` int(11) unsigned DEFAULT NULL,
`owner` tinyint(1) unsigned DEFAULT NULL,
`edited_content` tinyint(1) unsigned DEFAULT NULL,
`edited_title` tinyint(1) unsigned DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `index_foreignkey_ticket_department` (`department_id`),
KEY `index_foreignkey_ticket_author` (`author_id`),
KEY `index_foreignkey_ticket_author_staff` (`author_staff_id`),
KEY `index_foreignkey_ticket_owner` (`owner_id`),
CONSTRAINT `c_fk_ticket_author_id` FOREIGN KEY (`author_id`) REFERENCES `user` (`id`) ON DELETE SET NULL ON UPDATE SET NULL,
CONSTRAINT `c_fk_ticket_author_staff_id` FOREIGN KEY (`author_staff_id`) REFERENCES `staff` (`id`) ON DELETE SET NULL ON UPDATE SET NULL,
CONSTRAINT `c_fk_ticket_department_id` FOREIGN KEY (`department_id`) REFERENCES `department` (`id`) ON DELETE SET NULL ON UPDATE SET NULL,
CONSTRAINT `c_fk_ticket_owner_id` FOREIGN KEY (`owner_id`) REFERENCES `staff` (`id`) ON DELETE SET NULL ON UPDATE SET NULL
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Table structure for table `ticket_user`
--
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE IF NOT EXISTS `ticket_user` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`ticket_id` int(11) unsigned DEFAULT NULL,
`user_id` int(11) unsigned DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `UQ_f73b0a7296c1f9101e14c7c4bd6476b9f9a6a2b7` (`ticket_id`,`user_id`),
KEY `index_foreignkey_ticket_user_ticket` (`ticket_id`),
KEY `index_foreignkey_ticket_user_user` (`user_id`),
CONSTRAINT `c_fk_ticket_user_ticket_id` FOREIGN KEY (`ticket_id`) REFERENCES `ticket` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT `c_fk_ticket_user_user_id` FOREIGN KEY (`user_id`) REFERENCES `user` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Table structure for table `ticketevent`
--
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE IF NOT EXISTS `ticketevent` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`type` varchar(191) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`content` varchar(191) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`date` double DEFAULT NULL,
`ticket_id` int(11) unsigned DEFAULT NULL,
`author_staff_id` int(11) unsigned DEFAULT NULL,
`file` tinyint(1) unsigned DEFAULT NULL,
`private` int(11) unsigned DEFAULT NULL,
`author_user_id` int(11) unsigned DEFAULT NULL,
`edited_content` tinyint(1) unsigned DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `index_foreignkey_ticketevent_ticket` (`ticket_id`),
KEY `index_foreignkey_ticketevent_author_staff` (`author_staff_id`),
KEY `index_foreignkey_ticketevent_author_user` (`author_user_id`),
CONSTRAINT `c_fk_ticketevent_author_staff_id` FOREIGN KEY (`author_staff_id`) REFERENCES `staff` (`id`) ON DELETE SET NULL ON UPDATE SET NULL,
CONSTRAINT `c_fk_ticketevent_author_user_id` FOREIGN KEY (`author_user_id`) REFERENCES `user` (`id`) ON DELETE SET NULL ON UPDATE SET NULL,
CONSTRAINT `c_fk_ticketevent_ticket_id` FOREIGN KEY (`ticket_id`) REFERENCES `ticket` (`id`) ON DELETE SET NULL ON UPDATE SET NULL
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Table structure for table `topic`
--
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE IF NOT EXISTS `topic` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`name` varchar(191) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`icon` varchar(191) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`icon_color` varchar(191) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`private` int(11) unsigned DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Table structure for table `user`
--
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE IF NOT EXISTS `user` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`email` varchar(191) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`password` varchar(191) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`name` varchar(191) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`signup_date` double DEFAULT NULL,
`tickets` int(11) unsigned DEFAULT NULL,
`verification_token` varchar(191) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`disabled` int(11) unsigned DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;
/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
-- Dump completed on 2020-01-18 20:58:21

View File

@ -9,6 +9,8 @@ if(defined('MYSQL_HOST') && defined('MYSQL_DATABASE') && defined('MYSQL_USER') &
if(!defined('MYSQL_PORT')) define('MYSQL_PORT', '3306');
RedBean::setup('mysql:host='. MYSQL_HOST . ';port=' . MYSQL_PORT . ';dbname=' . MYSQL_DATABASE , MYSQL_USER, MYSQL_PASSWORD);
RedBean::setAutoResolve(true);
// TODO: Implement freeze
// RedBean::freeze();
}
// SLIM FRAMEWORK

View File

@ -6,7 +6,15 @@ abstract class DataStore {
protected $properties = [];
public static function isTableEmpty() {
return (RedBean::count(static::TABLE) === 0);
try {
return (RedBean::count(static::TABLE) === 0);
} catch(\Exception $e) {
return true;
}
}
public static function getFetchAs() {
return [];
}
public static function getDataStore($value, $property = 'id') {
@ -112,7 +120,13 @@ abstract class DataStore {
}
private function parseBeanProp($prop) {
$parsedProp = $this->_bean[$prop];
$fetchAs = static::getFetchAs();
if(array_key_exists($prop, $fetchAs)) {
$parsedProp = $this->_bean->fetchAs($fetchAs[$prop])[$prop];
} else {
$parsedProp = $this->_bean[$prop];
}
if (strpos($prop, 'List')) {
$parsedProp = DataStoreList::getList($this->getListType($prop), $parsedProp);

View File

@ -56,6 +56,14 @@ class Ticket extends DataStore {
);
}
public static function getFetchAs() {
return [
'author' => 'user',
'authorStaff' => 'staff',
'owner' => 'staff',
];
}
public static function getTicket($value, $property = 'id') {
return parent::getDataStore($value, $property);
}

View File

@ -65,6 +65,13 @@ class Ticketevent extends DataStore {
];
}
public static function getFetchAs() {
return [
'authorUser' => 'user',
'authorStaff' => 'staff'
];
}
public function getAuthor() {
if($this->authorUser) {
return $this->authorUser;

View File

@ -71,6 +71,7 @@ require './ticket/add-tag.rb'
require './ticket/delete-tag.rb'
require './ticket/edit-comment.rb'
require './ticket/edit-title.rb'
require './system/custom-fields.rb'
require './system/disable-user-system.rb'
require './ticket/search.rb'
# require './system/get-stats.rb'