diff options
author | hashworks <mail@hashworks.net> | 2017-07-10 21:00:41 +0200 |
---|---|---|
committer | hashworks <mail@hashworks.net> | 2017-07-10 21:00:41 +0200 |
commit | cfcf6afd4f61769db72dd3927d1cea85c2603191 (patch) | |
tree | bd418edb69694471569796e37318058a5abdeffc /application | |
parent | 02ffa0c14f1c7401344eee4acde46c000f91bcc7 (diff) |
Update filesizes after changing filesize db type
This updates all wrong filesizes after db migration 19 (`filesize` type
change to `bigint`). It will only update files with a filesize of
2147483647 byte since the database set the max integer value as the
filesize if the file was > 2147483647 byte.
Diffstat (limited to 'application')
-rw-r--r-- | application/migrations/019_change_filesize_type.php | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/application/migrations/019_change_filesize_type.php b/application/migrations/019_change_filesize_type.php index 327d8dcae..47a998452 100644 --- a/application/migrations/019_change_filesize_type.php +++ b/application/migrations/019_change_filesize_type.php @@ -18,6 +18,29 @@ class Migration_change_filesize_type extends CI_Migration { MODIFY `filesize` bigint; '); } + + $chunk = 500; + + $total = $this->db->count_all("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() |