From 8e3618f4128e419e1522e48ccec27082d30e4de4 Mon Sep 17 00:00:00 2001 From: Frederic Guillot Date: Fri, 22 May 2015 11:54:45 -0400 Subject: Increase length of attachments file names (and truncate if really too long) --- app/Model/File.php | 2 +- app/Schema/Mysql.php | 7 ++++++- tests/units/FileTest.php | 31 +++++++++++++++++++++++++++++++ 3 files changed, 38 insertions(+), 2 deletions(-) create mode 100644 tests/units/FileTest.php diff --git a/app/Model/File.php b/app/Model/File.php index fe417d48..cb1e4792 100644 --- a/app/Model/File.php +++ b/app/Model/File.php @@ -92,7 +92,7 @@ class File extends Base return $this->db->table(self::TABLE)->save(array( 'task_id' => $task_id, - 'name' => $name, + 'name' => substr($name, 0, 255), 'path' => $path, 'is_image' => $is_image ? '1' : '0', 'size' => $size, diff --git a/app/Schema/Mysql.php b/app/Schema/Mysql.php index aa611a6e..a65525c8 100644 --- a/app/Schema/Mysql.php +++ b/app/Schema/Mysql.php @@ -6,7 +6,12 @@ use PDO; use Core\Security; use Model\Link; -const VERSION = 71; +const VERSION = 72; + +function version_72($pdo) +{ + $pdo->exec('ALTER TABLE files MODIFY name VARCHAR(255)'); +} function version_71($pdo) { diff --git a/tests/units/FileTest.php b/tests/units/FileTest.php new file mode 100644 index 00000000..5e882fdb --- /dev/null +++ b/tests/units/FileTest.php @@ -0,0 +1,31 @@ +container); + $f = new File($this->container); + $tc = new TaskCreation($this->container); + + $this->assertEquals(1, $p->create(array('name' => 'test'))); + $this->assertEquals(1, $tc->create(array('project_id' => 1, 'title' => 'test'))); + + $this->assertTrue($f->create(1, 'test', '/tmp/foo', false, 10)); + $this->assertTrue($f->create(1, str_repeat('a', 1000), '/tmp/foo', false, 10)); + + $files = $f->getAll(1); + $this->assertNotEmpty($files); + $this->assertCount(2, $files); + + $this->assertEquals(str_repeat('a', 255), $files[0]['name']); + $this->assertEquals('test', $files[1]['name']); + } +} -- cgit v1.2.3