Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
O
osticket
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
docker
osticket
Commits
fda938c6
Commit
fda938c6
authored
12 years ago
by
Jared Hancock
Browse files
Options
Downloads
Patches
Plain Diff
Simplify interface to AttachmentChunkedData
parent
bf957037
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
include/class.file.php
+9
-36
9 additions, 36 deletions
include/class.file.php
include/upgrader/sql/15b30765-dd0022fb.patch.sql
+2
-15
2 additions, 15 deletions
include/upgrader/sql/15b30765-dd0022fb.patch.sql
with
11 additions
and
51 deletions
include/class.file.php
+
9
−
36
View file @
fda938c6
...
@@ -230,7 +230,7 @@ class AttachmentFile {
...
@@ -230,7 +230,7 @@ class AttachmentFile {
* in the FILE_CHUNK_TABLE to overcome the max_allowed_packet limitation of
* in the FILE_CHUNK_TABLE to overcome the max_allowed_packet limitation of
* LOB fields in the MySQL database
* LOB fields in the MySQL database
*/
*/
define
(
'CHUNK_SIZE'
,
256
*
1024
);
# Beware if you change this...
define
(
'CHUNK_SIZE'
,
500
*
1024
);
# Beware if you change this...
class
AttachmentChunkedData
{
class
AttachmentChunkedData
{
function
AttachmentChunkedData
(
$file
)
{
function
AttachmentChunkedData
(
$file
)
{
$this
->
_file
=
$file
;
$this
->
_file
=
$file
;
...
@@ -244,51 +244,24 @@ class AttachmentChunkedData {
...
@@ -244,51 +244,24 @@ class AttachmentChunkedData {
return
$length
;
return
$length
;
}
}
function
seek
(
$location
)
{
$this
->
_pos
=
$location
;
}
function
tell
()
{
return
$this
->
_pos
;
}
function
read
(
$length
=
CHUNK_SIZE
)
{
function
read
(
$length
=
CHUNK_SIZE
)
{
# Read requested length of data from attachment chunks
# Read requested length of data from attachment chunks
$buffer
=
''
;
list
(
$buffer
)
=
@
db_fetch_row
(
db_query
(
while
(
$length
>
0
)
{
'SELECT filedata FROM '
.
FILE_CHUNK_TABLE
.
' WHERE file_id='
$chunk_id
=
floor
(
$this
->
_pos
/
CHUNK_SIZE
);
.
db_input
(
$this
->
_file
)
.
' AND chunk_id='
.
$this
->
_pos
++
));
$start
=
$this
->
_pos
%
CHUNK_SIZE
;
$size
=
min
(
$length
,
CHUNK_SIZE
-
$start
);
list
(
$block
)
=
@
db_fetch_row
(
db_query
(
'SELECT SUBSTR(filedata, '
.
(
$start
+
1
)
.
', '
.
$size
.
') FROM '
.
FILE_CHUNK_TABLE
.
' WHERE file_id='
.
db_input
(
$this
->
_file
)
.
' AND chunk_id='
.
$chunk_id
));
if
(
!
$block
)
return
false
;
$buffer
.
=
$block
;
$this
->
_pos
+=
$size
;
$length
-=
$size
;
}
return
$buffer
;
return
$buffer
;
}
}
function
write
(
$what
)
{
function
write
(
$what
,
$chunk_size
=
CHUNK_SIZE
)
{
# Figure out the remaining part of the current chunk (use CHUNK_SIZE
# and $this->_pos, increment pointer into $what and continue to end
# of what
$offset
=
0
;
$offset
=
0
;
for
(;;)
{
for
(;;)
{
$start
=
$this
->
_pos
%
CHUNK_SIZE
;
$block
=
substr
(
$what
,
$offset
,
$chunk_size
);
$size
=
CHUNK_SIZE
-
$start
;
$block
=
substr
(
$what
,
$offset
,
$size
);
if
(
!
$block
)
break
;
if
(
!
$block
)
break
;
if
(
!
db_query
(
'REPLACE INTO '
.
FILE_CHUNK_TABLE
if
(
!
db_query
(
'REPLACE INTO '
.
FILE_CHUNK_TABLE
.
' SET filedata=INSERT(filedata, '
.
(
$start
+
1
)
.
','
.
$size
.
' SET filedata=0x'
.
bin2hex
(
$block
)
.
', file_id='
.
', 0x'
.
bin2hex
(
$block
)
.
db_input
(
$this
->
_file
)
.
', chunk_id='
.
db_input
(
$this
->
_pos
++
)))
.
'), file_id='
.
db_input
(
$this
->
_file
)
.
', chunk_id='
.
floor
(
$this
->
_pos
/
CHUNK_SIZE
)))
return
false
;
return
false
;
$offset
+=
$size
;
$offset
+=
strlen
(
$block
);
$this
->
_pos
+=
strlen
(
$block
);
}
}
return
true
;
return
true
;
}
}
...
...
This diff is collapsed.
Click to expand it.
include/upgrader/sql/15b30765-dd0022fb.patch.sql
+
2
−
15
View file @
fda938c6
...
@@ -6,15 +6,6 @@
...
@@ -6,15 +6,6 @@
*
*
*/
*/
CREATE
TABLE
`%TABLE_PREFIX%T_file_chunk_id`
(
`id`
int
(
11
)
);
-- Support up to 16MB attachments
INSERT
INTO
`%TABLE_PREFIX%T_file_chunk_id`
VALUES
(
0
),
(
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
),
(
52
),
(
53
),
(
54
),
(
55
),
(
56
),
(
57
),
(
58
),
(
59
),
(
60
),
(
61
),
(
62
),
(
63
);
DROP
TABLE
IF
EXISTS
`%TABLE_PREFIX%file_chunk`
;
DROP
TABLE
IF
EXISTS
`%TABLE_PREFIX%file_chunk`
;
CREATE
TABLE
`%TABLE_PREFIX%file_chunk`
(
CREATE
TABLE
`%TABLE_PREFIX%file_chunk`
(
`file_id`
int
(
11
)
NOT
NULL
,
`file_id`
int
(
11
)
NOT
NULL
,
...
@@ -24,16 +15,12 @@ CREATE TABLE `%TABLE_PREFIX%file_chunk` (
...
@@ -24,16 +15,12 @@ CREATE TABLE `%TABLE_PREFIX%file_chunk` (
)
ENGINE
=
MyISAM
DEFAULT
CHARSET
=
utf8
;
)
ENGINE
=
MyISAM
DEFAULT
CHARSET
=
utf8
;
INSERT
INTO
`%TABLE_PREFIX%file_chunk`
(
`file_id`
,
`chunk_id`
,
`filedata`
)
INSERT
INTO
`%TABLE_PREFIX%file_chunk`
(
`file_id`
,
`chunk_id`
,
`filedata`
)
SELECT
T1
.
`id`
,
T2
.
`id`
,
SELECT
`id`
,
0
,
`filedata`
SUBSTR
(
T1
.
`filedata`
,
T2
.
`id`
*
256
*
1024
+
1
,
256
*
1024
)
FROM
`%TABLE_PREFIX%file`
;
FROM
`%TABLE_PREFIX%file`
T1
,
`%TABLE_PREFIX%T_file_chunk_id`
T2
WHERE
T2
.
`id`
*
256
*
1024
<
LENGTH
(
T1
.
`filedata`
);
ALTER
TABLE
`%TABLE_PREFIX%file`
DROP
COLUMN
`filedata`
;
ALTER
TABLE
`%TABLE_PREFIX%file`
DROP
COLUMN
`filedata`
;
OPTIMIZE
TABLE
`%TABLE_PREFIX%file`
;
OPTIMIZE
TABLE
`%TABLE_PREFIX%file`
;
DROP
TABLE
`%TABLE_PREFIX%T_file_chunk_id`
;
-- Finished with patch
-- Finished with patch
UPDATE
`%TABLE_PREFIX%config`
UPDATE
`%TABLE_PREFIX%config`
SET
`schema_signature`
=
'dd0022fb14892c0bb6a9700392df2de7'
;
SET
`schema_signature`
=
'dd0022fb14892c0bb6a9700392df2de7'
;
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment