aboutsummaryrefslogtreecommitdiff
path: root/classes/File.php
diff options
context:
space:
mode:
authorCamil Staps2016-08-01 09:15:36 +0200
committerCamil Staps2016-08-01 09:15:36 +0200
commit923aac957cc28723c622570d46d2a915c75df06f (patch)
treee4c6a3683f0f0781ed9545feb922e41a2e8d1e8b /classes/File.php
parentInternationalisation: email subjects (diff)
Removed duplicate code
Diffstat (limited to 'classes/File.php')
-rw-r--r--classes/File.php23
1 files changed, 22 insertions, 1 deletions
diff --git a/classes/File.php b/classes/File.php
index e400d25..ad44448 100644
--- a/classes/File.php
+++ b/classes/File.php
@@ -26,10 +26,31 @@
*/
class File extends Model {
/** {@inheritDoc} */
- public
+ public static
$table = 'file',
$fillable_columns = ['filename', 'secret_key'];
+ /** {@inheritDoc} */
+ public static function create($pdo, $values) {
+ $filename = $values[0];
+
+ // Check for file existence
+ if (file_exists(Constants::files_folder . $filename)) {
+ throw new Exception("$filename already exists.");
+ }
+
+ // Try to create the file
+ if (file_put_contents(Constants::files_folder . $filename, '') === false) {
+ throw new Exception("$filename could not be created. Check the permissions.");
+ }
+
+ if (count($values) < count(static::$fillable_columns)) {
+ $values[] = self::getRandomSecretKey();
+ }
+
+ return parent::create($pdo, $values);
+ }
+
/**
* A random max-63-char string that can be used as secret_key
*