Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
Curriculum-Request
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
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
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
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Tim Steiner
Curriculum-Request
Commits
31250e44
Commit
31250e44
authored
18 years ago
by
Tim Steiner
Browse files
Options
Downloads
Patches
Plain Diff
Adds support for storing files too large for the database.
parent
0ea3509c
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
application/models/rows/File.php
+55
-0
55 additions, 0 deletions
application/models/rows/File.php
application/models/rows/RequestFile.php
+7
-7
7 additions, 7 deletions
application/models/rows/RequestFile.php
application/models/tables/Files.php
+1
-0
1 addition, 0 deletions
application/models/tables/Files.php
with
63 additions
and
7 deletions
application/models/rows/File.php
0 → 100644
+
55
−
0
View file @
31250e44
<?php
/**
*
* @tableClass Files
*
*/
class
File
extends
Nmc_Db_Table_Row
{
public
function
__construct
(
$config
=
array
())
{
parent
::
__construct
(
$config
);
if
(
strlen
(
$this
->
data
)
==
0
&&
file_exists
(
$this
->
_getPath
()
.
DIRECTORY_SEPARATOR
.
$this
->
hash
))
{
$this
->
data
=
file_get_contents
(
$this
->
_getPath
()
.
DIRECTORY_SEPARATOR
.
$this
->
hash
);
}
}
public
function
_save
()
{
$oldHash
=
$this
->
hash
;
$this
->
hash
=
hash
(
'whirlpool'
,
$this
->
data
);
if
(
strlen
(
$this
->
data
)
>
(
$this
->
_getMaxPacketSize
()
/
2
)
/* && $oldHash != $this->hash*/
)
{
@
mkdir
(
$this
->
_getPath
(),
0755
,
true
);
file_put_contents
(
$this
->
_getPath
()
.
DIRECTORY_SEPARATOR
.
$this
->
hash
,
$this
->
data
);
$this
->
data
=
''
;
}
parent
::
_save
();
}
protected
function
_getMaxPacketSize
()
{
return
1024
*
1024
;
$db
=
Files
::
getInstance
()
->
getAdapter
();
$max_packet
=
$db
->
query
(
'SELECT @@max_allowed_packet'
)
->
fetchAll
();
$max_packet
=
$max_packet
[
0
][
'@@max_allowed_packet'
];
return
$max_packet
;
}
protected
function
_getPath
()
{
$path
=
APPLICATION_PATH
.
DIRECTORY_SEPARATOR
.
'uploads'
.
DIRECTORY_SEPARATOR
.
substr
(
$this
->
hash
,
0
,
1
)
.
DIRECTORY_SEPARATOR
.
substr
(
$this
->
hash
,
1
,
2
);
return
$path
;
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
application/models/rows/RequestFile.php
+
7
−
7
View file @
31250e44
<?php
class
RequestFile
extends
Nmc_Db_Table_Row
/**
*
* @tableClass RequestFiles
* @foreignKey file
*
*/
class
RequestFile
extends
File
{
const
SYLLABUS_TYPE
=
'syllabus'
;
const
CROSSLIST_MEMO_TYPE
=
'crosslist memo'
;
const
IS_NARRATIVE_TYPE
=
'is_narrative'
;
const
OTHER_TYPE
=
'other'
;
public
function
__construct
(
$config
=
array
())
{
parent
::
__construct
(
$config
);
$this
->
_registerRelation
(
new
Nmc_Db_Table_Relation_Extend
(
Files
::
getInstance
(),
$this
,
'file'
));
}
}
?>
\ No newline at end of file
This diff is collapsed.
Click to expand it.
application/models/tables/Files.php
+
1
−
0
View file @
31250e44
...
...
@@ -3,6 +3,7 @@
/**
*
* @primary file_id
* @rowClass File
*
*/
class
Files
extends
Nmc_Db_Table
...
...
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