2017-04-26 06:40:52 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
use Vn\Lib;
|
|
|
|
use Vn\Lib\UserException;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Uploads a access module.
|
|
|
|
*/
|
2018-05-23 10:14:20 +00:00
|
|
|
class AccessVersion extends Vn\Web\JsonRequest {
|
2017-04-26 06:40:52 +00:00
|
|
|
const PARAMS = [
|
|
|
|
'appName'
|
|
|
|
,'newVersion'
|
|
|
|
];
|
|
|
|
|
2018-05-23 10:14:20 +00:00
|
|
|
function run($db) {
|
2017-04-26 06:40:52 +00:00
|
|
|
// Checks for file errors.
|
|
|
|
|
|
|
|
$moduleFile = $_FILES['moduleFile'];
|
|
|
|
|
2018-05-23 10:14:20 +00:00
|
|
|
if (empty($moduleFile['name']))
|
|
|
|
throw new UserException(s('File not choosed'));
|
2017-04-26 06:40:52 +00:00
|
|
|
|
2018-05-23 10:14:20 +00:00
|
|
|
if ($moduleFile['error'] != 0) {
|
|
|
|
switch ($_FILES['image']['error']) {
|
2017-04-26 06:40:52 +00:00
|
|
|
case UPLOAD_ERR_INI_SIZE:
|
|
|
|
$message = 'ErrIniSize';
|
|
|
|
break;
|
|
|
|
case UPLOAD_ERR_FORM_SIZE:
|
|
|
|
$message = 'ErrFormSize';
|
|
|
|
break;
|
|
|
|
case UPLOAD_ERR_PARTIAL:
|
|
|
|
$message = 'ErrPartial';
|
|
|
|
break;
|
|
|
|
case UPLOAD_ERR_NO_FILE:
|
|
|
|
$message = 'ErrNoFile';
|
|
|
|
break;
|
|
|
|
case UPLOAD_ERR_NO_TMP_DIR:
|
|
|
|
$message = 'ErrNoTmpDir';
|
|
|
|
break;
|
|
|
|
case UPLOAD_ERR_CANT_WRITE:
|
|
|
|
$message = 'ErrCantWrite';
|
|
|
|
break;
|
|
|
|
case UPLOAD_ERR_EXTENSION:
|
|
|
|
$message = 'ErrExtension';
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
$message = 'ErrDefault';
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2018-05-23 10:14:20 +00:00
|
|
|
throw new Lib\Exception(s($message));
|
2017-04-26 06:40:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Defining parameters
|
|
|
|
|
|
|
|
$appName = $_REQUEST['appName'];
|
|
|
|
$newVersion = $_REQUEST['newVersion'];
|
|
|
|
|
2019-09-10 10:00:56 +00:00
|
|
|
$uploadDir = '/mnt/storage/vn-access';
|
2017-04-26 06:40:52 +00:00
|
|
|
$uploadFile = "$uploadDir/$appName.7z";
|
|
|
|
$archiveDir = "$uploadDir/.archive/$appName";
|
|
|
|
$archiveFile = "$archiveDir/$newVersion.7z";
|
|
|
|
|
|
|
|
// Updates the application
|
|
|
|
|
2018-05-23 10:14:20 +00:00
|
|
|
copy($moduleFile['tmp_name'], $archiveFile);
|
|
|
|
rename($moduleFile['tmp_name'], $uploadFile);
|
2020-01-23 12:52:38 +00:00
|
|
|
chmod($archiveFile, 0644);
|
2017-04-26 06:40:52 +00:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|