• Resolved antrouss

    (@antrouss)


    After I updated to wodpress 4.2 my plugin is not able to create all my custom tables. It creates only teachers and holidays tables. Here is my code:

    register_activation_hook( __FILE__, 'utt_install' );
    function utt_install(){
    
        require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
    
        global $wpdb;
        $periodsTable=$wpdb->prefix."utt_periods";
        $subjectsTable=$wpdb->prefix."utt_subjects";
        $groupsTable=$wpdb->prefix."utt_groups";
        $teachersTable=$wpdb->prefix."utt_teachers";
        $classroomsTable=$wpdb->prefix."utt_classrooms";
        $lessonsTable=$wpdb->prefix."utt_lessons";
        $holidaysTable=$wpdb->prefix."utt_holidays";
        $eventsTable=$wpdb->prefix."utt_events";
        $lessonsView=$wpdb->prefix."utt_lessons_view";
    
        $sql = "CREATE TABLE IF NOT EXISTS <code>$periodsTable</code> (
                <code>periodID</code> INT UNSIGNED NOT NULL AUTO_INCREMENT,
                <code>year</code> YEAR NOT NULL COMMENT 'το ?το? - ?τσι θα μπορε? να κρατηθε? και ιστορικ? σε β?θο? χρ?νου',
                <code>semester</code> ENUM('Ε','Χ') NOT NULL COMMENT 'Εαριν?, Χειμεριν?',
                PRIMARY KEY (<code>periodID</code>))
                ENGINE = InnoDB
                DEFAULT CHARACTER SET = utf8
                COLLATE = utf8_general_ci;";
        dbDelta($sql);
    
        $sql="CREATE TABLE IF NOT EXISTS <code>$subjectsTable</code> (
                <code>subjectID</code> INT UNSIGNED NOT NULL AUTO_INCREMENT,
                <code>title</code> VARCHAR(64) NOT NULL COMMENT 'το επ?σημο ?νομα του μαθ?ματο?',
                <code>type</code> ENUM('Θ','Ε','ΑΠ') NOT NULL COMMENT 'Θεωρ?α, Εργαστ?ριο, ?σκηση-Πρ?ξη',
                <code>semester</code> TINYINT UNSIGNED NOT NULL COMMENT 'το εξ?μηνο σπουδ?ν στο οπο?ο απευθ?νεται το μ?θημα',
                <code>is_enabled</code> TINYINT(1) NOT NULL DEFAULT 1 COMMENT 'εαν το μ?θημα ε?ναι ενεργ? - η εφαρμογ? θα προβ?λει μ?νο τα ενεργ? μαθ?ματα',
                <code>color</code> VARCHAR(45) NOT NULL COMMENT 'Το χρ?μα που θα εμφαν?ζεται στο πρ?γραμμα.',
                PRIMARY KEY (<code>subjectID</code>))
                ENGINE = InnoDB
                DEFAULT CHARACTER SET = utf8
                COLLATE = utf8_general_ci;";
        dbDelta($sql);
    
        $sql="CREATE TABLE IF NOT EXISTS <code>$groupsTable</code> (
                <code>groupID</code> INT UNSIGNED NOT NULL AUTO_INCREMENT COMMENT 'μοναδικ? μ?σω ευρετηρ?ου UQ - για χρ?ση ω? FKey στον Lessons',
                <code>periodID</code> INT UNSIGNED NOT NULL COMMENT 'FKey απ? Periods',
                <code>subjectID</code> INT UNSIGNED NOT NULL COMMENT 'FKey απ? Subjects',
                <code>groupName</code> VARCHAR(20) NOT NULL COMMENT 'το ?νομα τη? ομ?δα? (εργαστηριακ??, κτλ)',
                PRIMARY KEY (<code>periodID</code>, <code>subjectID</code>, <code>groupName</code>),
                INDEX <code>fk_Groups_Periods_idx</code> (<code>periodID</code> ASC),
                INDEX <code>fk_Groups_Subject1_idx</code> (<code>subjectID</code> ASC),
                UNIQUE INDEX <code>groupID_UNIQUE</code> (<code>groupID</code> ASC),
                CONSTRAINT <code>fk_Groups_Periods</code>
                FOREIGN KEY (<code>periodID</code>)
                REFERENCES <code>$periodsTable</code> (<code>periodID</code>)
                ON DELETE RESTRICT
                ON UPDATE CASCADE,
                CONSTRAINT <code>fk_Groups_Subjects</code>
                FOREIGN KEY (<code>subjectID</code>)
                REFERENCES <code>$subjectsTable</code> (<code>subjectID</code>)
                ON DELETE RESTRICT
                ON UPDATE CASCADE)
                ENGINE = InnoDB
                DEFAULT CHARACTER SET = utf8
                COLLATE = utf8_general_ci;";
        dbDelta($sql);
    
        $sql="CREATE TABLE IF NOT EXISTS <code>$teachersTable</code> (
                <code>teacherID</code> SMALLINT UNSIGNED NOT NULL AUTO_INCREMENT,
                <code>surname</code> VARCHAR(35) NOT NULL,
                <code>name</code> VARCHAR(35) NULL,
                PRIMARY KEY (<code>teacherID</code>))
                ENGINE = InnoDB
                DEFAULT CHARACTER SET = utf8
                COLLATE = utf8_general_ci;";
        dbDelta($sql);
    
        $sql="CREATE TABLE IF NOT EXISTS <code>$classroomsTable</code> (
                <code>classroomID</code> SMALLINT UNSIGNED NOT NULL AUTO_INCREMENT,
                <code>name</code> VARCHAR(35) NOT NULL,
                <code>type</code> ENUM('Δ','Ε') NOT NULL COMMENT 'Διαλ?ξεων, Εργαστηρ?ου',
                <code>is_available</code> TINYINT(1) NOT NULL DEFAULT 1,
                PRIMARY KEY (<code>classroomID</code>))
                ENGINE = InnoDB
                DEFAULT CHARACTER SET = utf8
                COLLATE = utf8_general_ci;";
        dbDelta($sql);
    
        $sql="CREATE TABLE IF NOT EXISTS <code>$lessonsTable</code> (
                <code>lessonID</code> INT UNSIGNED NOT NULL AUTO_INCREMENT,
                <code>groupID</code> INT UNSIGNED NOT NULL COMMENT 'FKey απ? Groups',
                <code>classroomID</code> SMALLINT UNSIGNED NOT NULL COMMENT 'FKey απ? Classrooms',
                <code>teacherID</code> SMALLINT UNSIGNED NOT NULL COMMENT 'FKey απ? Teachers',
                <code>start</code> DATETIME NOT NULL COMMENT 'το date part καθορ?ζει την ημερομην?α και το time part την ?ρα ?ναρξη?',
                <code>end</code> DATETIME NOT NULL,
                INDEX <code>fk_Lesson_Classrooms1_idx</code> (<code>classroomID</code> ASC),
                INDEX <code>fk_Lesson_Teachers1_idx</code> (<code>teacherID</code> ASC),
                PRIMARY KEY (<code>lessonID</code>),
                CONSTRAINT <code>fk_Lessons_Classrooms</code>
                FOREIGN KEY (<code>classroomID</code>)
                REFERENCES <code>$classroomsTable</code> (<code>classroomID</code>)
                ON DELETE RESTRICT
                ON UPDATE CASCADE,
                CONSTRAINT <code>fk_Lessons_Teachers</code>
                FOREIGN KEY (<code>teacherID</code>)
                REFERENCES <code>$teachersTable</code> (<code>teacherID</code>)
                ON DELETE RESTRICT
                ON UPDATE CASCADE,
                CONSTRAINT <code>fk_Lessons_Groups1</code>
                FOREIGN KEY (<code>groupID</code>)
                REFERENCES <code>$groupsTable</code> (<code>groupID</code>)
                ON DELETE RESTRICT
                ON UPDATE CASCADE)
                ENGINE = InnoDB
                DEFAULT CHARACTER SET = utf8
                COLLATE = utf8_general_ci;";
    
        dbDelta($sql);
    
        $sql="CREATE TABLE IF NOT EXISTS <code>$holidaysTable</code> (
                <code>holidayDate</code> DATE NOT NULL,
                <code>holidayName</code> VARCHAR(45) NOT NULL,
                PRIMARY KEY (<code>holidayDate</code>))
                ENGINE = InnoDB
                DEFAULT CHARACTER SET = utf8
                COLLATE = utf8_general_ci;";
        dbDelta($sql);
    
        $sql="CREATE TABLE IF NOT EXISTS <code>$eventsTable</code> (
                <code>eventID</code> INT UNSIGNED NOT NULL AUTO_INCREMENT,
                <code>eventType</code> VARCHAR(45) NOT NULL COMMENT 'Τ?πο? του συμβ?ντο?.',
                <code>eventTitle</code> VARCHAR(45) NOT NULL COMMENT 'Τ?τλο? του συμβ?ντο?',
                <code>eventDescr</code> VARCHAR(255) NULL COMMENT 'Περιγραφ? του συμβ?ντο?.',
                <code>classroomID</code> SMALLINT UNSIGNED NOT NULL COMMENT 'Fkey απ? classrooms',
                <code>eventStart</code> DATETIME NOT NULL COMMENT 'Ημερομην?α - ?ρα που αρχ?ζει το συμβ?ν.',
                <code>eventEnd</code> DATETIME NOT NULL COMMENT 'Ημερομην?α - ?ρα που τελει?νει το συμβ?ν.',
                PRIMARY KEY (<code>eventID</code>),
                INDEX <code>fk_wp_utt_events_wp_utt_classrooms1_idx</code> (<code>classroomID</code> ASC),
                CONSTRAINT <code>fk_wp_utt_events_wp_utt_classrooms1</code>
                FOREIGN KEY (<code>classroomID</code>)
                REFERENCES <code>$classroomsTable</code> (<code>classroomID</code>)
                ON DELETE RESTRICT
                ON UPDATE CASCADE)
                ENGINE = InnoDB
                DEFAULT CHARACTER SET = utf8
                COLLATE = utf8_general_ci;";
        dbDelta($sql);
    
        $wpdb->query("CREATE  OR REPLACE VIEW $lessonsView AS
                SELECT
                    periodID,
                    lessonID,
                    semester,
                    $lessonsTable.groupID,
                    $lessonsTable.classroomID,
                    $lessonsTable.teacherID,
                    start,
                    end,
                    groupName,
                    $subjectsTable.subjectID,
                    $subjectsTable.title AS subjectTitle,
                    $subjectsTable.type AS subjectType,
                    $classroomsTable.name AS classroomName,
                    $classroomsTable.type AS classroomType,
                    surname as teacherSurname,
                    $teachersTable.name as teacherName
                FROM
                    $lessonsTable,
                    $groupsTable,
                    $subjectsTable,
                    $classroomsTable,
                    $teachersTable
                WHERE
                    $lessonsTable.groupID = $groupsTable.groupID
                        AND $groupsTable.subjectID = $subjectsTable.subjectID
                        AND $lessonsTable.classroomID = $classroomsTable.classroomID
                        AND $lessonsTable.teacherID = $teachersTable.teacherID;");
    
    }

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter antrouss

    (@antrouss)

    Thread Starter antrouss

    (@antrouss)

    After a lot of research nothing worked. I found out that wordpress 4.2 is not accepting greek characters in sql create table. So I had to change all the enums and sql comments to english.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Can't create tables with my plugin after update’ is closed to new replies.