From 07c1d79f7c84a3c68d4a46614cde9929d5ef58e7 Mon Sep 17 00:00:00 2001
From: Jared Hancock <jared@osticket.com>
Date: Wed, 22 Jul 2015 15:34:54 -0500
Subject: [PATCH] oops: Fix upgrade crash

Also,
* use current year when no company name exists (yet)
* log a `created` timestamp for new files
* drop table %group during the upgrade
---
 include/class.file.php                                      | 1 +
 include/staff/login.tpl.php                                 | 2 +-
 include/staff/pwreset.login.php                             | 2 +-
 include/staff/pwreset.php                                   | 2 +-
 include/staff/pwreset.sent.php                              | 2 +-
 include/upgrader/streams/core/0d6099a6-98ad7d55.cleanup.sql | 1 +
 include/upgrader/streams/core/15b30765-dd0022fb.task.php    | 1 +
 include/upgrader/streams/core/1ee831c8-36f6b328.patch.sql   | 1 +
 include/upgrader/streams/core/1ee831c8-36f6b328.task.php    | 2 +-
 9 files changed, 9 insertions(+), 5 deletions(-)

diff --git a/include/class.file.php b/include/class.file.php
index c0b844bfc..d921d22dd 100644
--- a/include/class.file.php
+++ b/include/class.file.php
@@ -386,6 +386,7 @@ class AttachmentFile extends VerySimpleModel {
             'key' => $file['key'],
             'ft' => $ft ?: 'T',
             'signature' => $file['signature'],
+            'created' => SqlFunction::NOW(),
         ));
 
         if (isset($file['size']))
diff --git a/include/staff/login.tpl.php b/include/staff/login.tpl.php
index 3bb7a8fc2..6319d289b 100644
--- a/include/staff/login.tpl.php
+++ b/include/staff/login.tpl.php
@@ -47,7 +47,7 @@ if (count($ext_bks)) { ?>
 
     <div id="company">
         <div class="content">
-            <?php echo __('Copyright'); ?> &copy; <?php echo Format::htmlchars($ost->company); ?>
+            <?php echo __('Copyright'); ?> &copy; <?php echo Format::htmlchars($ost->company) ?: date('Y'); ?>
         </div>
     </div>
 </div>
diff --git a/include/staff/pwreset.login.php b/include/staff/pwreset.login.php
index 6eeb21b34..cc5d0ae89 100644
--- a/include/staff/pwreset.login.php
+++ b/include/staff/pwreset.login.php
@@ -29,7 +29,7 @@ $info = ($_POST)?Format::htmlchars($_POST):array();
 
     <div id="company">
         <div class="content">
-            <?php echo __('Copyright'); ?> &copy; <?php echo Format::htmlchars($ost->company); ?>
+            <?php echo __('Copyright'); ?> &copy; <?php echo Format::htmlchars($ost->company) ?: date('Y'); ?>
         </div>
     </div>
 </div>
diff --git a/include/staff/pwreset.php b/include/staff/pwreset.php
index 5a82af009..eddd22a0c 100644
--- a/include/staff/pwreset.php
+++ b/include/staff/pwreset.php
@@ -27,7 +27,7 @@ $info = ($_POST && $errors)?Format::htmlchars($_POST):array();
 
     <div id="company">
         <div class="content">
-            <?php echo __('Copyright'); ?> &copy; <?php echo Format::htmlchars($ost->company); ?>
+            <?php echo __('Copyright'); ?> &copy; <?php echo Format::htmlchars($ost->company) ?: date('Y'); ?>
         </div>
     </div>
 </div>
diff --git a/include/staff/pwreset.sent.php b/include/staff/pwreset.sent.php
index bb74b7b8b..0609f3416 100644
--- a/include/staff/pwreset.sent.php
+++ b/include/staff/pwreset.sent.php
@@ -25,7 +25,7 @@ $info = ($_POST && $errors)?Format::htmlchars($_POST):array();
 
     <div id="company">
         <div class="content">
-            <?php echo __('Copyright'); ?> &copy; <?php echo Format::htmlchars($ost->company); ?>
+            <?php echo __('Copyright'); ?> &copy; <?php echo Format::htmlchars($ost->company) ?: date('Y'); ?>
         </div>
     </div>
 </div>
diff --git a/include/upgrader/streams/core/0d6099a6-98ad7d55.cleanup.sql b/include/upgrader/streams/core/0d6099a6-98ad7d55.cleanup.sql
index 362a94005..292d60528 100644
--- a/include/upgrader/streams/core/0d6099a6-98ad7d55.cleanup.sql
+++ b/include/upgrader/streams/core/0d6099a6-98ad7d55.cleanup.sql
@@ -6,6 +6,7 @@
  */
 
 DROP TABLE IF EXISTS `%TABLE_PREFIX%group_dept_access`;
+DROP TABLE IF EXISTS `%TABLE_PREFIX%group`;
 
 -- Drop `updated` if it exists (it stayed in the install script after it was
 -- removed from the update path
diff --git a/include/upgrader/streams/core/15b30765-dd0022fb.task.php b/include/upgrader/streams/core/15b30765-dd0022fb.task.php
index 755c57fe7..970136b1b 100644
--- a/include/upgrader/streams/core/15b30765-dd0022fb.task.php
+++ b/include/upgrader/streams/core/15b30765-dd0022fb.task.php
@@ -245,6 +245,7 @@ class AttachmentMigrater extends MigrationTask {
             'hash' => $file['hash'],
             'bk' => '6',
             'attrs' => $file['path'],
+            'created' => date('Y-m-d H:i:s', Misc::dbtime(filemtime($file['path']))),
         ));
     }
 }
diff --git a/include/upgrader/streams/core/1ee831c8-36f6b328.patch.sql b/include/upgrader/streams/core/1ee831c8-36f6b328.patch.sql
index 850441a57..a60fae20c 100644
--- a/include/upgrader/streams/core/1ee831c8-36f6b328.patch.sql
+++ b/include/upgrader/streams/core/1ee831c8-36f6b328.patch.sql
@@ -26,6 +26,7 @@ ALTER TABLE `%TABLE_PREFIX%staff`
     ADD `role_id` INT(10) UNSIGNED NOT NULL DEFAULT '0' AFTER `dept_id`;
 
 ALTER TABLE  `%TABLE_PREFIX%groups`
+    RENAME TO `%TABLE_PREFIX%group`,
     CHANGE  `group_id`  `id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
     ADD  `role_id` INT UNSIGNED NOT NULL DEFAULT  '0' AFTER  `id`;
 
diff --git a/include/upgrader/streams/core/1ee831c8-36f6b328.task.php b/include/upgrader/streams/core/1ee831c8-36f6b328.task.php
index f70c4e2bf..982f690e7 100644
--- a/include/upgrader/streams/core/1ee831c8-36f6b328.task.php
+++ b/include/upgrader/streams/core/1ee831c8-36f6b328.task.php
@@ -1,5 +1,5 @@
 <?php
-define('GROUP_TABLE', TABLE_PREFIX.'groups');
+define('GROUP_TABLE', TABLE_PREFIX.'group');
 define('GROUP_DEPT_TABLE', TABLE_PREFIX.'group_dept_access');
 class Group extends VerySimpleModel {
     static $meta = array(
-- 
GitLab