Add new constants: FILES_DIR and DEBUG_FILE

This commit is contained in:
Frederic Guillot 2015-01-25 10:47:21 -05:00
parent bf65a95851
commit 655d75a3cf
5 changed files with 23 additions and 21 deletions

View File

@ -2,8 +2,6 @@
namespace Controller;
use Model\File as FileModel;
/**
* File controller
*
@ -54,7 +52,7 @@ class File extends Base
{
$task = $this->getTask();
$file = $this->file->getById($this->request->getIntegerParam('file_id'));
$filename = FileModel::BASE_PATH.$file['path'];
$filename = FILES_DIR.$file['path'];
if ($file['task_id'] == $task['id'] && file_exists($filename)) {
$this->response->forceDownload($file['name']);
@ -91,7 +89,7 @@ class File extends Base
{
$task = $this->getTask();
$file = $this->file->getById($this->request->getIntegerParam('file_id'));
$filename = FileModel::BASE_PATH.$file['path'];
$filename = FILES_DIR.$file['path'];
if ($file['task_id'] == $task['id'] && file_exists($filename)) {
$metadata = getimagesize($filename);

View File

@ -19,13 +19,6 @@ class File extends Base
*/
const TABLE = 'task_has_files';
/**
* Directory where are stored files
*
* @var string
*/
const BASE_PATH = 'data/files/';
/**
* Events
*
@ -56,7 +49,7 @@ class File extends Base
{
$file = $this->getbyId($file_id);
if (! empty($file) && @unlink(self::BASE_PATH.$file['path'])) {
if (! empty($file) && @unlink(FILES_DIR.$file['path'])) {
return $this->db->table(self::TABLE)->eq('id', $file_id)->remove();
}
@ -152,14 +145,14 @@ class File extends Base
*/
public function setup()
{
if (! is_dir(self::BASE_PATH)) {
if (! mkdir(self::BASE_PATH, 0755, true)) {
die('Unable to create the upload directory: "'.self::BASE_PATH.'"');
if (! is_dir(FILES_DIR)) {
if (! mkdir(FILES_DIR, 0755, true)) {
die('Unable to create the upload directory: "'.FILES_DIR.'"');
}
}
if (! is_writable(self::BASE_PATH)) {
die('The directory "'.self::BASE_PATH.'" must be writeable by your webserver user');
if (! is_writable(FILES_DIR)) {
die('The directory "'.FILES_DIR.'" must be writeable by your webserver user');
}
}
@ -187,15 +180,15 @@ class File extends Base
$uploaded_filename = $_FILES[$form_name]['tmp_name'][$key];
$destination_filename = $this->generatePath($project_id, $task_id, $original_filename);
@mkdir(self::BASE_PATH.dirname($destination_filename), 0755, true);
@mkdir(FILES_DIR.dirname($destination_filename), 0755, true);
if (@move_uploaded_file($uploaded_filename, self::BASE_PATH.$destination_filename)) {
if (@move_uploaded_file($uploaded_filename, FILES_DIR.$destination_filename)) {
$result[] = $this->create(
$task_id,
$original_filename,
$destination_filename,
$this->isImage(self::BASE_PATH.$destination_filename)
$this->isImage(FILES_DIR.$destination_filename)
);
}
}

View File

@ -16,7 +16,7 @@ class LoggingProvider implements ServiceProviderInterface
$logger->setLogger(new Syslog('kanboard'));
if (DEBUG) {
$logger->setLogger(new File(__DIR__.'/../../data/debug.log'));
$logger->setLogger(new File(DEBUG_FILE));
}
$container['logger'] = $logger;

View File

@ -2,6 +2,7 @@
// Enable/disable debug
defined('DEBUG') or define('DEBUG', false);
defined('DEBUG_FILE') or define('DEBUG_FILE', 'data/debug.log');
// Application version
defined('APP_VERSION') or define('APP_VERSION', 'master');
@ -64,3 +65,7 @@ defined('MAIL_SENDMAIL_COMMAND') or define('MAIL_SENDMAIL_COMMAND', '/usr/sbin/s
// Enable or disable "Strict-Transport-Security" HTTP header
defined('ENABLE_HSTS') or define('ENABLE_HSTS', true);
// Default files directory
defined('FILES_DIR') or define('FILES_DIR', 'data/files/');

View File

@ -3,6 +3,12 @@
// Enable/Disable debug
define('DEBUG', false);
// Debug file path
define('DEBUG_FILE', 'data/debug.log');
// Folder for uploaded files, don't forget the trailing slash
define('FILES_DIR', 'data/files/');
// E-mail address for the "From" header (notifications)
define('MAIL_FROM', 'notifications@kanboard.local');