From 7b68c99453ae71a8eb4f8cb96f3b27dadabddacc Mon Sep 17 00:00:00 2001 From: Peter Rotich <peter@osticket.com> Date: Tue, 21 Feb 2017 16:29:54 +0000 Subject: [PATCH] Chunk long text body --- include/class.thread.php | 45 ++++++++++++++++--- include/class.thread_actions.php | 2 +- .../templates/thread-entry-edit.tmpl.php | 3 +- 3 files changed, 43 insertions(+), 7 deletions(-) diff --git a/include/class.thread.php b/include/class.thread.php index 164624d35..3911f714b 100644 --- a/include/class.thread.php +++ b/include/class.thread.php @@ -601,6 +601,7 @@ implements TemplateVariable { const PERM_EDIT = 'thread.edit'; var $_headers; + var $_body; var $_thread; var $_actions; var $is_autoreply; @@ -676,9 +677,21 @@ implements TemplateVariable { } function getBody() { - return ThreadEntryBody::fromFormattedText($this->body, $this->format, - array('balanced' => $this->hasFlag(self::FLAG_BALANCED)) - ); + + if (!isset($this->_body)) { + $body = $this->body; + if ($body == null && $this->getNumAttachments()) { + foreach ($this->attachments as $a) + if ($a->inline && ($f=$a->getFile())) + $body .= $f->getData(); + } + + $this->_body = ThreadEntryBody::fromFormattedText($body, $this->format, + array('balanced' => $this->hasFlag(self::FLAG_BALANCED)) + ); + } + + return $this->_body; } function setBody($body) { @@ -1396,14 +1409,36 @@ implements TemplateVariable { // Set body here after it was rewritten to capture the stored file // keys (above) - $entry->body = $body; - if (!$entry->save()) + // Store body as an attachment if bigger than allowed packet size + if (mb_strlen($body) >= 65000) { // 65,535 chars in text field. + $entry->body = NULL; + $file = array( + 'type' => 'text/html', + 'name' => md5($body).'.txt', + 'data' => $body, + ); + + if (($AF = AttachmentFile::create($file))) { + $attached_files[$file['key']] = array( + 'id' => $AF->getId(), + 'inline' => true, + 'file' => $AF); + } else { + $entry->body = $body; + } + } else { + $entry->body = $body; + + } + + if (!$entry->save(true)) return false; // Associate the attached files with this new entry $entry->createAttachments($attached_files); + // Save mail message id, if available $entry->saveEmailInfo($vars); diff --git a/include/class.thread_actions.php b/include/class.thread_actions.php index 6650ee098..b585c8cb7 100644 --- a/include/class.thread_actions.php +++ b/include/class.thread_actions.php @@ -123,7 +123,7 @@ JS $old = $this->entry; $new = ThreadEntryBody::fromFormattedText($_POST['body'], $old->format); - if ($new->getClean() == $old->body) + if ($new->getClean() == $old->getBody()) // No update was performed return $old; diff --git a/include/staff/templates/thread-entry-edit.tmpl.php b/include/staff/templates/thread-entry-edit.tmpl.php index 3f2d0fe56..14a13b63e 100644 --- a/include/staff/templates/thread-entry-edit.tmpl.php +++ b/include/staff/templates/thread-entry-edit.tmpl.php @@ -34,7 +34,8 @@ class="large <?php if ($cfg->isRichTextEnabled() && $this->entry->format == 'html') echo 'richtext'; - ?>"><?php echo htmlspecialchars(Format::viewableImages($this->entry->body)); + ?>"><?php echo htmlspecialchars(Format::viewableImages( + (string) $this->entry->getBody())); ?></textarea> <?php if ($this->entry->type == 'R') { ?> -- GitLab