diff options
author | Florian Pritz <bluewind@xinu.at> | 2017-07-11 10:25:28 +0200 |
---|---|---|
committer | Florian Pritz <bluewind@xinu.at> | 2017-07-11 10:25:28 +0200 |
commit | 7404267544848502d053ed2391832e799df3ec5c (patch) | |
tree | 755e410be7a5bdfd06b4452e0f13c3233713c96c | |
parent | 5674bd05d10a91c1e70d03fed419379b7a5ed0c8 (diff) | |
parent | 0a1e76f365dbd90eee9c72d81d898e1a0ddf630c (diff) |
Merge branch 'bugfix/filesizeType' of https://github.com/hashworks/filebin into dev
-rw-r--r-- | application/config/migration.php | 2 | ||||
-rw-r--r-- | application/migrations/019_change_filesize_type.php | 51 |
2 files changed, 52 insertions, 1 deletions
diff --git a/application/config/migration.php b/application/config/migration.php index 659907cb8..45ce7711b 100644 --- a/application/config/migration.php +++ b/application/config/migration.php @@ -21,7 +21,7 @@ $config['migration_enabled'] = true; | be upgraded / downgraded to. | */ -$config['migration_version'] = 18; +$config['migration_version'] = 19; /* diff --git a/application/migrations/019_change_filesize_type.php b/application/migrations/019_change_filesize_type.php new file mode 100644 index 000000000..33abf89ed --- /dev/null +++ b/application/migrations/019_change_filesize_type.php @@ -0,0 +1,51 @@ +<?php +defined('BASEPATH') OR exit('No direct script access allowed'); + +class Migration_change_filesize_type extends CI_Migration { + + public function up() + { + $prefix = $this->db->dbprefix; + + if ($this->db->dbdriver == 'postgre') { + $this->db->query(' + ALTER TABLE "'.$prefix.'file_storage" + ALTER "filesize" TYPE bigint; + '); + } else { + $this->db->query(' + ALTER TABLE `'.$prefix.'file_storage` + MODIFY `filesize` bigint; + '); + } + + $chunk = 500; + + $this->db->where('filesize', 2147483647); + $total = $this->db->count_all_results("file_storage"); + + for ($limit = 0; $limit < $total; $limit += $chunk) { + $query = $this->db->select('hash, id') + ->from('file_storage') + ->where('filesize', 2147483647) + ->limit($chunk, $limit) + ->get()->result_array(); + + foreach ($query as $key => $item) { + $data_id = $item["hash"].'-'.$item['id']; + $filesize = filesize($this->mfile->file($data_id)); + + $this->db->where('id', $item['id']) + ->set(array( + 'filesize' => $filesize, + )) + ->update('file_storage'); + } + } + } + + public function down() + { + throw new \exceptions\ApiException("migration/downgrade-not-supported", "downgrade not supported"); + } +} |