Пример #1
0
 /**
  * upgrade360
  * 
  * Upgrade database to version 3.6.0
  * 
  * @return boolean
  */
 function upgrade360()
 {
     $errorMessage = sprintf(T_('Could not upgrade database to version %s.'), '3.6.0');
     // google client id
     $google_id_fixed = false;
     $sql = "SELECT `name` FROM `fcms_config` WHERE `name` = 'google_client_id'";
     $row = $this->fcmsDatabase->getRow($sql);
     if ($row === false) {
         $this->fcmsError->setMessage($errorMessage);
         return false;
     }
     if (!empty($row)) {
         $google_id_fixed = true;
     }
     if (!$google_id_fixed) {
         $sql = "INSERT INTO `fcms_config` (`name`, `value`)\n                    VALUES ('google_client_id', NULL)";
         if (!$this->fcmsDatabase->insert($sql)) {
             $this->fcmsError->setMessage($errorMessage);
             return false;
         }
     }
     // google client secret
     $google_secret_fixed = false;
     $sql = "SELECT `name` FROM `fcms_config` WHERE `name` = 'google_client_secret'";
     $row = $this->fcmsDatabase->getRow($sql);
     if ($row === false) {
         $this->fcmsError->setMessage($errorMessage);
         return false;
     }
     if (!empty($row)) {
         $google_secret_fixed = true;
     }
     if (!$google_secret_fixed) {
         $sql = "INSERT INTO `fcms_config` (`name`, `value`)\n                    VALUES ('google_client_secret', NULL)";
         if (!$this->fcmsDatabase->insert($sql)) {
             $this->fcmsError->setMessage($errorMessage);
             return false;
         }
     }
     // google user setting
     $google_user_fixed = false;
     $youtube_user_exists = false;
     $sql = "SHOW COLUMNS FROM `fcms_user_settings`";
     $rows = $this->fcmsDatabase->getRows($sql);
     if ($rows === false) {
         $this->fcmsError->setMessage($errorMessage);
         return false;
     }
     foreach ($rows as $r) {
         if ($r['Field'] == 'google_session_token') {
             $google_user_fixed = true;
         }
         if ($r['Field'] == 'youtube_session_token') {
             $youtube_user_exists = true;
         }
     }
     if (!$google_user_fixed) {
         // change youtube column to google
         if ($youtube_user_exists) {
             $sql = "ALTER TABLE `fcms_user_settings`\n                        CHANGE COLUMN `youtube_session_token` `google_session_token` VARCHAR(255) NULL";
             if (!$this->fcmsDatabase->alter($sql)) {
                 $this->fcmsError->setMessage($errorMessage);
                 return false;
             }
             // Set all existing youtube session to null
             $sql = "UPDATE `fcms_user_settings`\n                        SET `google_session_token` = NULL";
             if (!$this->fcmsDatabase->update($sql)) {
                 $this->fcmsError->setMessage($errorMessage);
                 return false;
             }
         } else {
             $sql = "ALTER TABLE `fcms_user_settings`\n                        ADD COLUMN `google_session_token` VARCHAR(255) NULL";
             if (!$this->fcmsDatabase->alter($sql)) {
                 $this->fcmsError->setMessage($errorMessage);
                 return false;
             }
         }
     }
     // google admin nav
     $google_nav_fixed = false;
     $sql = "SELECT `link` FROM `fcms_navigation` WHERE `link` = 'admin_google'";
     $row = $this->fcmsDatabase->getRow($sql);
     if ($row === false) {
         $this->fcmsError->setMessage($errorMessage);
         return false;
     }
     if (!empty($row)) {
         $google_nav_fixed = true;
     }
     if (!$google_nav_fixed) {
         // changing youtube to google?
         $change_youtube = false;
         $sql = "SELECT `link` FROM `fcms_navigation` WHERE `link` = 'admin_youtube'";
         $row = $this->fcmsDatabase->getRow($sql);
         if ($row === false) {
             $this->fcmsError->setMessage($errorMessage);
             return false;
         }
         if (!empty($row)) {
             $change_youtube = true;
         }
         if ($change_youtube) {
             $sql = "UPDATE `fcms_navigation`\n                        SET `link` = 'admin_google'\n                        WHERE `link` = 'admin_youtube'";
             if (!$this->fcmsDatabase->update($sql)) {
                 $this->fcmsError->setMessage($errorMessage);
                 return false;
             }
         } else {
             $adminOrder = getNextAdminNavigationOrder();
             $sql = "INSERT INTO `fcms_navigation` (`link`, `col`, `order`, `req`)\n                        VALUES ('admin_google', 6, ?, 1)";
             if (!$this->fcmsDatabase->insert($sql, $adminOrder)) {
                 $this->fcmsError->setMessage($errorMessage);
                 return false;
             }
         }
     }
     // facebook user id
     $facebook_user_id_fixed = false;
     $sql = "SHOW COLUMNS FROM `fcms_user_settings`";
     $rows = $this->fcmsDatabase->getRows($sql);
     if ($rows === false) {
         $this->fcmsError->setMessage($errorMessage);
         return false;
     }
     foreach ($rows as $r) {
         if ($r['Field'] == 'fb_user_id') {
             $facebook_user_id_fixed = true;
         }
     }
     if (!$facebook_user_id_fixed) {
         $sql = "ALTER TABLE `fcms_user_settings` ADD `fb_user_id` VARCHAR(255) NULL";
         if (!$this->fcmsDatabase->alter($sql)) {
             $this->fcmsError->setMessage($errorMessage);
             return false;
         }
     }
     return true;
 }
Пример #2
0
 /**
  * upgrade300
  * 
  * Upgrade database to version 3.0.
  * 
  * @return boolean
  */
 function upgrade300()
 {
     global $cfg_mysql_db;
     $errorMessage = sprintf(T_('Could not upgrade database to version %s.'), '3.0');
     // instagram client id
     $instagram_client_id_fixed = false;
     $sql = "SELECT `name` \n                FROM `fcms_config` \n                WHERE `name` = 'instagram_client_id'";
     $row = $this->fcmsDatabase->getRow($sql);
     if ($row === false) {
         $this->fcmsError->setMessage($errorMessage);
         return false;
     }
     if (!empty($row)) {
         $instagram_client_id_fixed = true;
     }
     if (!$instagram_client_id_fixed) {
         $sql = "INSERT INTO `fcms_config` (`name`, `value`)\n                    VALUES ('instagram_client_id', NULL)";
         if (!$this->fcmsDatabase->insert($sql)) {
             $this->fcmsError->setMessage($errorMessage);
             return false;
         }
     }
     // instagram client secret
     $instagram_client_secret_fixed = false;
     $sql = "SELECT `name` \n                FROM `fcms_config` \n                WHERE `name` = 'instagram_client_secret'";
     $row = $this->fcmsDatabase->getRow($sql);
     if ($row === false) {
         $this->fcmsError->setMessage($errorMessage);
         return false;
     }
     if (!empty($row)) {
         $instagram_client_secret_fixed = true;
     }
     if (!$instagram_client_secret_fixed) {
         $sql = "INSERT INTO `fcms_config` (`name`, `value`)\n                    VALUES ('instagram_client_secret', NULL)";
         if (!$this->fcmsDatabase->insert($sql)) {
             $this->fcmsError->setMessage($errorMessage);
             return false;
         }
     }
     // instagram admin nav
     $instagram_admin_nav_fixed = false;
     $sql = "SELECT `link`\n                FROM `fcms_navigation`\n                WHERE `link` = 'admin_instagram'";
     $row = $this->fcmsDatabase->getRow($sql);
     if ($row === false) {
         $this->fcmsError->setMessage($errorMessage);
         return false;
     }
     if (!empty($row)) {
         $instagram_admin_nav_fixed = true;
     }
     if (!$instagram_admin_nav_fixed) {
         $adminOrder = getNextAdminNavigationOrder();
         $sql = "INSERT INTO `fcms_navigation` (`link`, `col`, `order`, `req`)\n                    VALUES ('admin_instagram', 6, ?, 1)";
         if (!$this->fcmsDatabase->insert($sql, $adminOrder)) {
             $this->fcmsError->setMessage($errorMessage);
             return false;
         }
     }
     // instagram user access code
     $instagram_user_fixed = false;
     $sql = "SHOW COLUMNS FROM `fcms_user_settings`";
     $rows = $this->fcmsDatabase->getRows($sql);
     if ($rows === false) {
         $this->fcmsError->setMessage($errorMessage);
         return false;
     }
     foreach ($rows as $r) {
         if ($r['Field'] == 'instagram_access_token') {
             $instagram_user_fixed = true;
         }
     }
     if (!$instagram_user_fixed) {
         $sql = "ALTER TABLE `fcms_user_settings` \n                    ADD `instagram_access_token` VARCHAR(255) NULL";
         if (!$this->fcmsDatabase->alter($sql)) {
             $this->fcmsError->setMessage($errorMessage);
             return false;
         }
     }
     // external
     $external_fixed = false;
     $sql = "SHOW COLUMNS FROM `fcms_gallery_photos`";
     $rows = $this->fcmsDatabase->getRows($sql);
     if ($rows === false) {
         $this->fcmsError->setMessage($errorMessage);
         return false;
     }
     foreach ($rows as $r) {
         if ($r['Field'] == 'external_id') {
             $external_fixed = true;
         }
     }
     if (!$external_fixed) {
         $sql = "ALTER TABLE `fcms_gallery_photos` \n                    ADD `external_id` INT(11) DEFAULT NULL AFTER `filename`";
         if (!$this->fcmsDatabase->alter($sql)) {
             $this->fcmsError->setMessage($errorMessage);
             return false;
         }
     }
     // external photos
     $external_photos_fixed = false;
     $sql = "SHOW TABLES FROM `{$cfg_mysql_db}`";
     $rows = $this->fcmsDatabase->getRows($sql);
     if ($rows === false) {
         $this->fcmsError->setMessage($errorMessage);
         return false;
     }
     foreach ($rows as $r) {
         if ($r[0] == 'fcms_gallery_external_photo') {
             $external_photos_fixed = true;
         }
     }
     if (!$external_photos_fixed) {
         $sql = "CREATE TABLE `fcms_gallery_external_photo` (\n                        `id` INT(11) NOT NULL AUTO_INCREMENT, \n                        `source_id` VARCHAR(255) NOT NULL,\n                        `thumbnail` VARCHAR(255) NOT NULL, \n                        `medium` VARCHAR(255) NOT NULL, \n                        `full` VARCHAR(255) NOT NULL, \n                        PRIMARY KEY (`id`)\n                    ) \n                    ENGINE=InnoDB DEFAULT CHARSET=utf8";
         if (!$this->fcmsDatabase->execute($sql)) {
             $this->fcmsError->setMessage($errorMessage);
             return false;
         }
     }
     // Rename gallery photo comment
     $photo_com_fixed = false;
     $sql = "SHOW TABLES FROM `{$cfg_mysql_db}`";
     $rows = $this->fcmsDatabase->getRows($sql);
     if ($rows === false) {
         $this->fcmsError->setMessage($errorMessage);
         return false;
     }
     foreach ($rows as $r) {
         if ($r[0] == 'fcms_gallery_photo_comment') {
             $photo_com_fixed = true;
         }
     }
     if (!$photo_com_fixed) {
         $sql = "RENAME TABLE `fcms_gallery_comments` TO `fcms_gallery_photo_comment`";
         if (!$this->fcmsDatabase->execute($sql)) {
             $this->fcmsError->setMessage($errorMessage);
             return false;
         }
     }
     // Gallery category comments
     $cat_com_fixed = false;
     $sql = "SHOW TABLES FROM `{$cfg_mysql_db}`";
     $rows = $this->fcmsDatabase->getRows($sql);
     if ($rows === false) {
         $this->fcmsError->setMessage($errorMessage);
         return false;
     }
     foreach ($rows as $r) {
         if ($r[0] == 'fcms_gallery_category_comment') {
             $cat_com_fixed = true;
         }
     }
     if (!$cat_com_fixed) {
         $sql = "CREATE TABLE `fcms_gallery_category_comment` (\n                        `id` INT(11) NOT NULL AUTO_INCREMENT, \n                        `category_id` INT(11) NOT NULL, \n                        `comment` TEXT NOT NULL, \n                        `created` TIMESTAMP NOT NULL DEFAULT '0000-00-00 00:00:00', \n                        `created_id` INT(11) NOT NULL, \n                        PRIMARY KEY (`id`)\n                    ) \n                    ENGINE=InnoDB DEFAULT CHARSET=utf8";
         if (!$this->fcmsDatabase->execute($sql)) {
             $this->fcmsError->setMessage($errorMessage);
             return false;
         }
     }
     // instagram automatic
     $instagram_auto_upload_fixed = false;
     $sql = "SHOW COLUMNS FROM `fcms_user_settings`";
     $rows = $this->fcmsDatabase->getRows($sql);
     if ($rows === false) {
         $this->fcmsError->setMessage($errorMessage);
         return false;
     }
     foreach ($rows as $r) {
         if ($r['Field'] == 'instagram_auto_upload') {
             $instagram_auto_upload_fixed = true;
         }
     }
     if (!$instagram_auto_upload_fixed) {
         $sql = "ALTER TABLE `fcms_user_settings` \n                    ADD `instagram_auto_upload` TINYINT(1) DEFAULT 0";
         if (!$this->fcmsDatabase->alter($sql)) {
             $this->fcmsError->setMessage($errorMessage);
             return false;
         }
     }
     // instagram scheduler
     $instagram_sched_fixed = false;
     $sql = "SELECT `type`\n                FROM `fcms_schedule` \n                WHERE `type` = 'instagram' \n                LIMIT 1";
     $row = $this->fcmsDatabase->getRow($sql);
     if ($row === false) {
         $this->fcmsError->setMessage($errorMessage);
         return false;
     }
     if (!empty($row)) {
         $instagram_sched_fixed = true;
     }
     if (!$instagram_sched_fixed) {
         $sql = "INSERT INTO `fcms_schedule` (`type`, `repeat`)\n                    VALUES ('instagram', 'hourly')";
         if (!$this->fcmsDatabase->insert($sql)) {
             $this->fcmsError->setMessage($errorMessage);
             return false;
         }
     }
     return true;
 }