blob: 33abf89ed388e044905f58217a44b6e297d3a0c5 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
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");
}
}
|