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'];
|
|
|
|
|
2020-01-23 13:28:12 +00:00
|
|
|
$accessDir = _DATA_DIR .'/'. $this->app->getName() .'/vn-access';
|
|
|
|
$headFile = "$accessDir/$appName.7z";
|
|
|
|
$archiveRelPath = ".archive/$appName/$newVersion.7z";
|
|
|
|
$archiveFullPath = "$accessDir/$archiveRelPath";
|
2017-04-26 06:40:52 +00:00
|
|
|
|
|
|
|
// Updates the application
|
|
|
|
|
2020-01-23 13:28:12 +00:00
|
|
|
rename($moduleFile['tmp_name'], $archiveFullPath);
|
|
|
|
chmod($archiveFullPath, 0644);
|
|
|
|
|
|
|
|
@unlink ($headFile);
|
|
|
|
symlink($headFile, $archiveRelPath);
|
2017-04-26 06:40:52 +00:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|