Browse Source

MySQL entry content MEDIUMBLOB (#2551)

Fix https://github.com/FreshRSS/FreshRSS/issues/2448
Alexandre Alapetite 6 years ago
parent
commit
38932ee3bb
3 changed files with 29 additions and 3 deletions
  1. 1 1
      app/Models/DatabaseDAO.php
  2. 26 0
      app/Models/EntryDAO.php
  3. 2 2
      app/SQL/install.sql.mysql.php

+ 1 - 1
app/Models/DatabaseDAO.php

@@ -8,7 +8,7 @@ class FreshRSS_DatabaseDAO extends Minz_ModelPdo {
 	//MySQL error codes
 	const ER_BAD_FIELD_ERROR = '42S22';
 	const ER_BAD_TABLE_ERROR = '42S02';
-	const ER_TRUNCATED_WRONG_VALUE_FOR_FIELD = '1366';
+	const ER_DATA_TOO_LONG = '1406';
 
 	//MySQL InnoDB maximum index length for UTF8MB4
 	//https://dev.mysql.com/doc/refman/8.0/en/innodb-restrictions.html

+ 26 - 0
app/Models/EntryDAO.php

@@ -38,6 +38,25 @@ class FreshRSS_EntryDAO extends Minz_ModelPdo implements FreshRSS_Searchable {
 		return $ok;
 	}
 
+	private function updateToMediumBlob() {
+		if ($this->pdo->dbType() !== 'mysql') {
+			return false;
+		}
+		Minz_Log::warning('Update MySQL table to use MEDIUMBLOB...');
+
+		$sql = <<<'SQL'
+ALTER TABLE `_entry` MODIFY `content_bin` MEDIUMBLOB;
+ALTER TABLE `_entrytmp` MODIFY `content_bin` MEDIUMBLOB;
+SQL;
+		try {
+			$ok = $this->pdo->exec($sql) !== false;
+		} catch (Exception $e) {
+			$ok = false;
+			Minz_Log::error(__method__ . ' error: ' . $e->getMessage());
+		}
+		return $ok;
+	}
+
 	//TODO: Move the database auto-updates to DatabaseDAO
 	protected function autoUpdateDb($errorInfo) {
 		if (isset($errorInfo[0])) {
@@ -50,6 +69,13 @@ class FreshRSS_EntryDAO extends Minz_ModelPdo implements FreshRSS_Searchable {
 				}
 			}
 		}
+		if (isset($errorInfo[1])) {
+			if ($errorInfo[1] == FreshRSS_DatabaseDAO::ER_DATA_TOO_LONG) {
+				if (stripos($errorInfo[2], 'content_bin') !== false) {
+					return $this->updateToMediumBlob();	//v1.15.0
+				}
+			}
+		}
 		return false;
 	}
 

+ 2 - 2
app/SQL/install.sql.mysql.php

@@ -43,7 +43,7 @@ CREATE TABLE IF NOT EXISTS `_entry` (
 	`guid` VARCHAR(760) CHARACTER SET latin1 COLLATE latin1_bin NOT NULL,	-- Maximum for UNIQUE is 767B
 	`title` VARCHAR(255) NOT NULL,
 	`author` VARCHAR(255),
-	`content_bin` BLOB,	-- v0.7
+	`content_bin` MEDIUMBLOB,	-- v0.7
 	`link` VARCHAR(1023) CHARACTER SET latin1 COLLATE latin1_bin NOT NULL,
 	`date` INT(11),	-- Until year 2038
 	`lastSeen` INT(11) DEFAULT 0,	-- v1.1.1, Until year 2038
@@ -71,7 +71,7 @@ CREATE TABLE IF NOT EXISTS `_entrytmp` (	-- v1.7
 	`guid` VARCHAR(760) CHARACTER SET latin1 COLLATE latin1_bin NOT NULL,
 	`title` VARCHAR(255) NOT NULL,
 	`author` VARCHAR(255),
-	`content_bin` BLOB,
+	`content_bin` MEDIUMBLOB,
 	`link` VARCHAR(1023) CHARACTER SET latin1 COLLATE latin1_bin NOT NULL,
 	`date` INT(11),
 	`lastSeen` INT(11) DEFAULT 0,