Fix plugin creation/update add Database::tableExists function

1.10.x
jmontoyaa 10 years ago
parent f8e8ec98a2
commit b603d25e43
  1. 12
      main/inc/lib/database.lib.php
  2. 278
      plugin/ticket/database.php
  3. 1
      plugin/ticket/src/ticket_plugin.class.php

@ -175,7 +175,7 @@ class Database
$listener = new \Gedmo\Sortable\SortableListener(); $listener = new \Gedmo\Sortable\SortableListener();
$entityManager->getEventManager()->addEventSubscriber($listener); $entityManager->getEventManager()->addEventSubscriber($listener);
$connection = $entityManager->getConnection(); $connection = $entityManager->getConnection();
$connection->executeQuery('set sql_mode=""');
$this->setConnection($connection); $this->setConnection($connection);
$this->setManager($entityManager); $this->setManager($entityManager);
} }
@ -662,4 +662,14 @@ class Database
$isSimpleMode $isSimpleMode
); );
} }
/**
* @param string $table
*
* @return bool
*/
public static function tableExists($table)
{
return self::getManager()->getConnection()->getSchemaManager()->tablesExist($table);
}
} }

@ -7,68 +7,71 @@
$objPlugin = TicketPlugin::create(); $objPlugin = TicketPlugin::create();
$table = Database::get_main_table(TABLE_TICKET_ASSIGNED_LOG); // Category
$sql = "CREATE TABLE IF NOT EXISTS ".$table." (
id int UNSIGNED NOT NULL AUTO_INCREMENT,
ticket_id int UNSIGNED DEFAULT NULL,
user_id int UNSIGNED DEFAULT NULL,
assigned_date datetime DEFAULT NULL,
sys_insert_user_id int UNSIGNED DEFAULT NULL,
PRIMARY KEY PK_ticket_assigned_log (id),
KEY FK_ticket_assigned_log (ticket_id))";
Database::query($sql);
//Category
$table = Database::get_main_table(TABLE_TICKET_CATEGORY); $table = Database::get_main_table(TABLE_TICKET_CATEGORY);
$sql = "CREATE TABLE IF NOT EXISTS ".$table." (
id int UNSIGNED NOT NULL AUTO_INCREMENT,
category_id char(3) NOT NULL,
project_id char(3) NOT NULL,
name varchar(100) NOT NULL,
description varchar(255) NOT NULL,
total_tickets int UNSIGNED NOT NULL DEFAULT '0',
course_required char(1) NOT NULL,
sys_insert_user_id int UNSIGNED DEFAULT NULL,
sys_insert_datetime datetime DEFAULT NULL,
sys_lastedit_user_id int UNSIGNED DEFAULT NULL,
sys_lastedit_datetime datetime DEFAULT NULL,
PRIMARY KEY (id))";
Database::query($sql);
//Default Categories if (!Database::tableExists($table)) {
$categoRow = array( $table = Database::get_main_table(TABLE_TICKET_ASSIGNED_LOG);
$objPlugin->get_lang('Enrollment') => $objPlugin->get_lang('TicketsAboutEnrollment'), $sql = "CREATE TABLE IF NOT EXISTS ".$table." (
$objPlugin->get_lang('GeneralInformation') => $objPlugin->get_lang('TicketsAboutGeneralInformation'), id int UNSIGNED NOT NULL AUTO_INCREMENT,
$objPlugin->get_lang('RequestAndPapework') => $objPlugin->get_lang('TicketsAboutRequestAndPapework'), ticket_id int UNSIGNED DEFAULT NULL,
$objPlugin->get_lang('AcademicIncidence') => $objPlugin->get_lang('TicketsAboutAcademicIncidence'), user_id int UNSIGNED DEFAULT NULL,
$objPlugin->get_lang('VirtualCampus') => $objPlugin->get_lang('TicketsAboutVirtualCampus'), assigned_date datetime DEFAULT NULL,
$objPlugin->get_lang('OnlineEvaluation') => $objPlugin->get_lang('TicketsAboutOnlineEvaluation') sys_insert_user_id int UNSIGNED DEFAULT NULL,
); PRIMARY KEY PK_ticket_assigned_log (id),
KEY FK_ticket_assigned_log (ticket_id))";
$i = 1; Database::query($sql);
foreach ($categoRow as $category => $description) {
//Online evaluation requires a course $sql = "CREATE TABLE IF NOT EXISTS $table (
if ($i == 6) { id int UNSIGNED NOT NULL AUTO_INCREMENT,
$attributes = array( category_id char(3) NOT NULL,
'id' => $i, project_id char(3) NOT NULL,
'category_id' => $i, name varchar(100) NOT NULL,
'name' => $category, description varchar(255) NOT NULL,
'description' => $description, total_tickets int UNSIGNED NOT NULL DEFAULT '0',
'project_id' => 1, course_required char(1) NOT NULL,
'course_required' => 1 sys_insert_user_id int UNSIGNED DEFAULT NULL,
); sys_insert_datetime datetime DEFAULT NULL,
} else { sys_lastedit_user_id int UNSIGNED DEFAULT NULL,
$attributes = array( sys_lastedit_datetime datetime DEFAULT NULL,
'id' => $i, PRIMARY KEY (id))";
'category_id' => $i, $result = Database::query($sql);
'project_id' => 1,
'description' => $description, // Default Categories
'name' => $category $categories = array(
); $objPlugin->get_lang('Enrollment') => $objPlugin->get_lang('TicketsAboutEnrollment'),
} $objPlugin->get_lang('GeneralInformation') => $objPlugin->get_lang('TicketsAboutGeneralInformation'),
$objPlugin->get_lang('RequestAndPapework') => $objPlugin->get_lang('TicketsAboutRequestAndPapework'),
$objPlugin->get_lang('AcademicIncidence') => $objPlugin->get_lang('TicketsAboutAcademicIncidence'),
$objPlugin->get_lang('VirtualCampus') => $objPlugin->get_lang('TicketsAboutVirtualCampus'),
$objPlugin->get_lang('OnlineEvaluation') => $objPlugin->get_lang('TicketsAboutOnlineEvaluation')
);
Database::insert($table, $attributes); $i = 1;
$i++; foreach ($categories as $category => $description) {
// Online evaluation requires a course
if ($i == 6) {
$attributes = array(
'id' => $i,
'category_id' => $i,
'name' => $category,
'description' => $description,
'project_id' => 1,
'course_required' => 1
);
} else {
$attributes = array(
'id' => $i,
'category_id' => $i,
'project_id' => 1,
'description' => $description,
'name' => $category
);
}
Database::insert($table, $attributes);
$i++;
}
} }
$table = Database::get_main_table(TABLE_TICKET_MESSAGE); $table = Database::get_main_table(TABLE_TICKET_MESSAGE);
@ -105,91 +108,98 @@ $sql = "CREATE TABLE IF NOT EXISTS ".$table." (
KEY ticket_message_id_fk (message_id))"; KEY ticket_message_id_fk (message_id))";
Database::query($sql); Database::query($sql);
//Priority // Priority
$table = Database::get_main_table(TABLE_TICKET_PRIORITY); $table = Database::get_main_table(TABLE_TICKET_PRIORITY);
$sql = "CREATE TABLE IF NOT EXISTS ".$table." (
id int UNSIGNED NOT NULL AUTO_INCREMENT,
priority_id char(3) NOT NULL,
priority varchar(20) DEFAULT NULL,
priority_desc varchar(250) DEFAULT NULL,
priority_color varchar(25) DEFAULT NULL,
priority_urgency tinyint DEFAULT NULL,
sys_insert_user_id int UNSIGNED DEFAULT NULL,
sys_insert_datetime datetime DEFAULT NULL,
sys_lastedit_user_id int UNSIGNED DEFAULT NULL,
sys_lastedit_datetime datetime DEFAULT NULL,
PRIMARY KEY (id))";
Database::query($sql);
//Default Priorities if (!Database::tableExists($table)) {
$defaultPriorities = array( $sql = "CREATE TABLE IF NOT EXISTS ".$table." (
'NRM' => $objPlugin->get_lang('PriorityNormal'), id int UNSIGNED NOT NULL AUTO_INCREMENT,
'HGH' => $objPlugin->get_lang('PriorityHigh'), priority_id char(3) NOT NULL,
'LOW' => $objPlugin->get_lang('PriorityLow') priority varchar(20) DEFAULT NULL,
); priority_desc varchar(250) DEFAULT NULL,
$i = 1; priority_color varchar(25) DEFAULT NULL,
foreach ($defaultPriorities as $pId => $priority) { priority_urgency tinyint DEFAULT NULL,
$attributes = array( sys_insert_user_id int UNSIGNED DEFAULT NULL,
'id' => $i, sys_insert_datetime datetime DEFAULT NULL,
'priority_id' => $pId, sys_lastedit_user_id int UNSIGNED DEFAULT NULL,
'priority' => $priority, sys_lastedit_datetime datetime DEFAULT NULL,
'priority_desc' => $priority PRIMARY KEY (id))";
Database::query($sql);
//Default Priorities
$defaultPriorities = array(
'NRM' => $objPlugin->get_lang('PriorityNormal'),
'HGH' => $objPlugin->get_lang('PriorityHigh'),
'LOW' => $objPlugin->get_lang('PriorityLow')
); );
Database::insert($table, $attributes); $i = 1;
$i++; foreach ($defaultPriorities as $pId => $priority) {
$attributes = array(
'id' => $i,
'priority_id' => $pId,
'priority' => $priority,
'priority_desc' => $priority
);
Database::insert($table, $attributes);
$i++;
}
} }
$table = Database::get_main_table(TABLE_TICKET_PROJECT); $table = Database::get_main_table(TABLE_TICKET_PROJECT);
$sql = "CREATE TABLE IF NOT EXISTS ".$table." ( if (!Database::tableExists($table)) {
id int UNSIGNED NOT NULL AUTO_INCREMENT, $sql = "CREATE TABLE IF NOT EXISTS ".$table." (
project_id char(3) NOT NULL, id int UNSIGNED NOT NULL AUTO_INCREMENT,
name varchar(50) DEFAULT NULL, project_id char(3) NOT NULL,
description varchar(250) DEFAULT NULL, name varchar(50) DEFAULT NULL,
email varchar(50) DEFAULT NULL, description varchar(250) DEFAULT NULL,
other_area tinyint NOT NULL DEFAULT '0', email varchar(50) DEFAULT NULL,
sys_insert_user_id int UNSIGNED DEFAULT NULL, other_area tinyint NOT NULL DEFAULT '0',
sys_insert_datetime datetime DEFAULT NULL, sys_insert_user_id int UNSIGNED DEFAULT NULL,
sys_lastedit_user_id int UNSIGNED DEFAULT NULL, sys_insert_datetime datetime DEFAULT NULL,
sys_lastedit_datetime datetime DEFAULT NULL, sys_lastedit_user_id int UNSIGNED DEFAULT NULL,
PRIMARY KEY (id))"; sys_lastedit_datetime datetime DEFAULT NULL,
Database::query($sql); PRIMARY KEY (id))";
Database::query($sql);
//Default Project Table Ticket
$attributes = array( //Default Project Table Ticket
'id' => 1, $attributes = array(
'project_id' => 1, 'id' => 1,
'name' => 'Ticket System' 'project_id' => 1,
); 'name' => 'Ticket System'
Database::insert($table, $attributes); );
Database::insert($table, $attributes);
}
//STATUS //STATUS
$table = Database::get_main_table(TABLE_TICKET_STATUS); $table = Database::get_main_table(TABLE_TICKET_STATUS);
$sql = "CREATE TABLE IF NOT EXISTS ".$table." ( if (!Database::tableExists($table)) {
id int UNSIGNED NOT NULL AUTO_INCREMENT, $sql = "CREATE TABLE IF NOT EXISTS ".$table." (
status_id char(3) NOT NULL, id int UNSIGNED NOT NULL AUTO_INCREMENT,
name varchar(100) NOT NULL, status_id char(3) NOT NULL,
description varchar(255) DEFAULT NULL, name varchar(100) NOT NULL,
PRIMARY KEY (id))"; description varchar(255) DEFAULT NULL,
Database::query($sql); PRIMARY KEY (id))";
Database::query($sql);
//Default status
$defaultStatus = array( //Default status
'NAT' => $objPlugin->get_lang('StatusNew'), $defaultStatus = array(
'PND' => $objPlugin->get_lang('StatusPending'), 'NAT' => $objPlugin->get_lang('StatusNew'),
'XCF' => $objPlugin->get_lang('StatusUnconfirmed'), 'PND' => $objPlugin->get_lang('StatusPending'),
'CLS' => $objPlugin->get_lang('StatusClose'), 'XCF' => $objPlugin->get_lang('StatusUnconfirmed'),
'REE' => $objPlugin->get_lang('StatusForwarded') 'CLS' => $objPlugin->get_lang('StatusClose'),
); 'REE' => $objPlugin->get_lang('StatusForwarded')
$i = 1;
foreach ($defaultStatus as $abr => $status) {
$attributes = array(
'id' => $i,
'status_id' => $abr,
'name' => $status
); );
Database::insert($table, $attributes);
$i ++; $i = 1;
foreach ($defaultStatus as $abr => $status) {
$attributes = array(
'id' => $i,
'status_id' => $abr,
'name' => $status
);
Database::insert($table, $attributes);
$i++;
}
} }
$table = Database::get_main_table(TABLE_TICKET_TICKET); $table = Database::get_main_table(TABLE_TICKET_TICKET);

@ -36,7 +36,6 @@ class TicketPlugin extends Plugin
{ {
// Create database tables and insert a Tab // Create database tables and insert a Tab
require_once api_get_path(SYS_PLUGIN_PATH) . PLUGIN_NAME . '/database.php'; require_once api_get_path(SYS_PLUGIN_PATH) . PLUGIN_NAME . '/database.php';
} }
/** /**

Loading…
Cancel
Save