Add upload setting see BT#11051

pull/2487/head
jmontoyaa 10 years ago
parent 7947ef70d6
commit 60d3ffb6b9
  1. 2
      main/admin/configure_plugin.php
  2. 1
      main/inc/lib/api.lib.php
  3. 2
      main/inc/lib/usermanager.lib.php
  4. 1
      plugin/vchamilo/lang/english.php
  5. 2
      plugin/vchamilo/lib/VChamiloPlugin.php
  6. 123
      plugin/vchamilo/lib/Virtual.php
  7. 7
      plugin/vchamilo/plugin.php
  8. 4
      plugin/vchamilo/views/editinstance.php
  9. 21
      plugin/vchamilo/views/manage.controller.php

@ -30,7 +30,6 @@ if (isset($pluginInfo['settings_form'])) {
/** @var FormValidator $form */
$form = $pluginInfo['settings_form'];
if (isset($form)) {
// We override the form attributes
$attributes = array('action' => $currentUrl, 'method' => 'POST');
$form->updateAttributes($attributes);
@ -65,6 +64,7 @@ if (isset($form)) {
);
foreach ($values as $key => $value) {
$value = trim($value);
api_add_setting(
$value,
Database::escape_string($pluginName . '_' . $key),

@ -821,6 +821,7 @@ function api_get_path($path = '', $configuration = [])
$paths[$root_web][SYS_ARCHIVE_PATH] = $virtualChamilo[SYS_ARCHIVE_PATH].'/';
$paths[$root_web][SYS_HOME_PATH] = $virtualChamilo[SYS_HOME_PATH].'/';
$paths[$root_web][SYS_COURSE_PATH] = $virtualChamilo[SYS_COURSE_PATH].'/';
$paths[$root_web][SYS_UPLOAD_PATH] = $virtualChamilo[SYS_UPLOAD_PATH].'/';
}
$isInitialized[$root_web] = true;

@ -1677,6 +1677,7 @@ class UserManager
$userInfo = api_get_user_info($user_id);
}
}
$imageWebPath = self::get_user_picture_path_by_id($user_id, 'web', $userInfo);
$pictureWebFile = $imageWebPath['file'];
$pictureWebDir = $imageWebPath['dir'];
@ -1781,6 +1782,7 @@ class UserManager
$path_info = self::getUserPicturePathById($user_id, 'system');
$path = $path_info['dir'];
// If this directory does not exist - we create it.
if (!file_exists($path)) {
mkdir($path, api_get_permissions_for_new_directories(), true);

@ -108,4 +108,5 @@ $strings['DatabaseDescription'] = 'A new database will be created with that name
$strings['RootWebExists'] = 'An instance with the same root web exists.';
$strings['ImportInstance'] = 'Import instance';
$strings['ConfigurationPath'] = 'Chamilo configuration path';
$strings['UploadRealRoot'] = 'Upload files';

@ -16,7 +16,7 @@ class VChamiloPlugin extends Plugin
*/
public function __construct()
{
parent::__construct('1.2', 'Valery Fremaux, Julio Montoya');
parent::__construct('1.3', 'Valery Fremaux, Julio Montoya');
}
/**

@ -42,9 +42,7 @@ class Virtual
if ($result->rowCount()) {
$data = $result->fetch();
$excludes = array('id', 'name');
$query = "SELECT * FROM settings_current WHERE subkey = 'vchamilo'";
$virtualSettings = $connection->executeQuery($query);
$virtualSettings = $virtualSettings->fetchAll();
@ -52,9 +50,13 @@ class Virtual
$homePath = '';
$coursePath = '';
$archivePath = '';
$uploadPath = '';
foreach ($virtualSettings as $setting) {
switch ($setting['variable']) {
case 'vchamilo_upload_real_root':
$uploadPath = $setting['selected_value'];
break;
case 'vchamilo_home_real_root':
$homePath = $setting['selected_value'];
break;
@ -67,7 +69,7 @@ class Virtual
}
}
if (empty($homePath) || empty($coursePath) || empty($archivePath)) {
if (empty($homePath) || empty($coursePath) || empty($archivePath) || empty($uploadPath)) {
echo 'Configure correctly the vchamilo plugin';
exit;
}
@ -84,6 +86,7 @@ class Virtual
$data['SYS_ARCHIVE_PATH'] = $archivePath.'/'.$data['slug'];
$data['SYS_HOME_PATH'] = $homePath.'/'.$data['slug'];
$data['SYS_COURSE_PATH'] = $coursePath.'/'.$data['slug'];
$data['SYS_UPLOAD_PATH'] = $uploadPath.'/'.$data['slug'];
$virtualChamilo = $data;
} else {
@ -588,11 +591,13 @@ class Virtual
$coursePath = self::getConfig('vchamilo', 'course_real_root').$separator.$vchamilo->slug;
$homePath = self::getConfig('vchamilo', 'home_real_root').$separator.$vchamilo->slug;
$archivePath = self::getConfig('vchamilo', 'archive_real_root').$separator.$vchamilo->slug;
$uploadPath = self::getConfig('vchamilo', 'upload_real_root').$separator.$vchamilo->slug;
// get the protocol free hostname
Display::addFlash(
Display::return_message("Copying {$templateDir}/data/courses => $coursePath")
);
copyDirTo(
self::chopLastSlash($templateDir.'/data/courses'),
self::chopLastSlash($coursePath),
@ -618,6 +623,17 @@ class Virtual
self::chopLastSlash($homePath),
false
);
// Upload
Display::addFlash(
Display::return_message("Copying {$templateDir}/data/upload => $uploadPath")
);
copyDirTo(
self::chopLastSlash($templateDir.'/data/upload'),
self::chopLastSlash($uploadPath),
false
);
}
/**
@ -669,6 +685,12 @@ class Virtual
echo $str;
}
/**
* @param $file
* @param $component
* @param bool $return
* @return string
*/
public static function requireCss($file, $component, $return = false)
{
global $_configuration, $htmlHeadXtra;
@ -728,10 +750,12 @@ class Virtual
$coursePath = self::getConfig('vchamilo', 'course_real_root');
$homePath = self::getConfig('vchamilo', 'home_real_root');
$archivePath = self::getConfig('vchamilo', 'archive_real_root');
$uploadPath = self::getConfig('vchamilo', 'upload_real_root');
$cmdSql = self::getConfig('vchamilo', 'cmd_mysql');
$cmdMySql = self::getConfig('vchamilo', 'cmd_mysqldump');
if (empty($coursePath) || empty($homePath) || empty($archivePath) || empty($cmdSql)|| empty($cmdMySql)) {
if (empty($coursePath) || empty($homePath) || empty($uploadPath) || empty($archivePath) || empty($cmdSql)|| empty($cmdMySql)) {
api_not_allowed(true, 'You have to complete all plugin settings.');
}
@ -742,13 +766,21 @@ class Virtual
$coursePath,
$homePath,
$archivePath,
$uploadPath,
$templatePath
];
foreach ($paths as $path) {
if (!is_writable($path)) {
$path = trim($path);
if (is_dir($path)) {
if (!is_writable($path)) {
Display::addFlash(
Display::return_message("Directory must have writable permissions: '$path'", 'warning')
);
};
} else {
Display::addFlash(
Display::return_message('Directory must have writable permissions: '.$path, 'warning')
Display::return_message("Directory doesn't exist: '$path'", 'warning')
);
}
}
@ -857,6 +889,12 @@ class Virtual
$slug = $virtualInfo['slug'];
} else {
$slug = $data->slug = Virtual::getSlugFromUrl($data->root_web);
if (empty($slug)) {
Display::addFlash(
Display::return_message('Cannot create slug from url: '.$data->root_web, 'error')
);
return ;
}
Database::insert($tablename, (array) $data);
}
@ -867,7 +905,6 @@ class Virtual
}
// or we continue with physical creation
self::createDirsFromSlug($slug);
if (!$template) {
@ -930,9 +967,11 @@ class Virtual
$fromCoursePath = $data->course_path;
$fromHomePath = $data->home_path;
$fromUploadPath = $data->upload_path;
unset($data->course_path);
unset($data->home_path);
unset($data->upload_path);
$newDatabase = clone $data;
$newDatabase->main_database = $newDatabase->import_to_main_database;
@ -978,9 +1017,7 @@ class Virtual
);
return false;
} else {
$connection = Virtual::getConnectionFromInstance($data);
$statement = $connection->query('SELECT * FROM settings_current');
$settings = $statement->fetchAll();
$settings = array_column($settings, 'selected_value', 'variable');
@ -1032,23 +1069,32 @@ class Virtual
$coursePath = self::getConfig('vchamilo', 'course_real_root').'/'.$slug;
$homePath = self::getConfig('vchamilo', 'home_real_root').'/'.$slug;
$uploadPath = self::getConfig('vchamilo', 'upload_real_root').'/'.$slug;
// Course
self::ctrace("Copy from '$fromCoursePath' to backup '$coursePath' ");
copyDirTo(
self::chopLastSlash($fromCoursePath),
self::chopLastSlash($coursePath),
false
);
// Home
self::ctrace("Copy from '$fromHomePath' to backup '$homePath' ");
copyDirTo(
self::chopLastSlash($fromHomePath),
self::chopLastSlash($homePath),
false
);
// Upload
self::ctrace("Copy from '$fromUploadPath' to backup '$uploadPath' ");
copyDirTo(
self::chopLastSlash($fromUploadPath),
self::chopLastSlash($uploadPath),
false
);
self::ctrace("Finished");
}
@ -1062,7 +1108,6 @@ class Virtual
$settings = $statement->fetchAll();
$settings = array_column($settings, 'selected_value', 'variable');
$settings['data_base'];
}
/**
@ -1094,54 +1139,32 @@ class Virtual
}
}
$absAlternateHome = Virtual::getConfig('vchamilo', 'home_real_root');
$absAlternateArchive = Virtual::getConfig('vchamilo', 'archive_real_root');
$absAlternateUpload = Virtual::getConfig('vchamilo', 'upload_real_root');
// absalternatehome is a vchamilo config setting that tells where the
// real physical storage for home pages are.
$homeDir = $absAlternateHome.'/'.$slug;
self::ctrace("Making home dir as $homeDir");
if (!is_dir($homeDir)) {
if (!mkdir($homeDir, 0777, true)) {
self::ctrace("Error creating home dir $homeDir \n");
}
}
// if real homedir IS NOT under chamilo install, link to it
// Seems not be necessary as we can globally link the whole Home container
/*
$standardlocation = $_configuration['root_sys'].'home/'.$home_folder; // where it should be
if ($homeDir != $standardlocation){
self::ctrace("Linking virtual home dir ");
if (!symlink($homeDir, $standardlocation)){
self::ctrace("could not link $standardlocation => $homeDir ");
}
}
*/
// create archive
$absAlternateArchive = Virtual::getConfig('vchamilo', 'archive_real_root');
$archiveDir = $absAlternateArchive.'/'.$slug;
$uploadDir = $absAlternateUpload.'/'.$slug;
self::ctrace("Making archive dir as $archiveDir ");
$dirs = [
$homeDir,
$archiveDir,
$uploadDir
];
if (!is_dir($archiveDir)) {
if (!mkdir($archiveDir, 0777, true)) {
self::ctrace("Error creating archive dir $archiveDir\n");
}
}
foreach ($dirs as $dir) {
self::ctrace("Making dir as $dir");
// if real archivedir IS NOT under chamilo install, link to it
// Seems not be necessary as we can globally link the whole Home container
/*
$standardlocation = $_configuration['root_sys'].'archive/'.$archive_folder; // where it should be
if ($archiveDir != $standardlocation){
self::ctrace("Linking virtual archive dir ");
if (!symlink($archiveDir, $standardlocation)){
self::ctrace("could not link $standardlocation => $archiveDir ");
if (!is_dir($dir)) {
if (!mkdir($dir, 0777, true)) {
self::ctrace("Error creating dir $dir \n");
}
}
}
*/
}
/**

@ -48,6 +48,7 @@ $form_settings = array(
'course_real_root' => Virtual::getConfig('vchamilo', 'course_real_root', true),
'archive_real_root' => Virtual::getConfig('vchamilo', 'archive_real_root', true),
'home_real_root' => Virtual::getConfig('vchamilo', 'home_real_root', true),
'upload_real_root' => Virtual::getConfig('vchamilo', 'upload_real_root', true),
);
$form->setDefaults($form_settings);
@ -79,6 +80,12 @@ $form->addElement(
[$plugin->get_lang('homerealroot'), 'Example: '.api_get_path(SYS_PATH).'var/home/']
);
$form->addElement(
'text',
'upload_real_root',
[$plugin->get_lang('UploadRealRoot'), 'Example: '.api_get_path(SYS_PATH).'var/upload/']
);
$form->addElement('header', $plugin->get_lang('mysqlcmds'));
$form->addElement('text', 'cmd_mysql', [$plugin->get_lang('mysqlcmd'), 'Example: /usr/bin/mysql']);
$form->addElement('text', 'cmd_mysqldump', [$plugin->get_lang('mysqldumpcmd'), 'Example: /usr/bin/mysqldump']);

@ -20,8 +20,8 @@ $registeronly = isset($_REQUEST['registeronly']) ? $_REQUEST['registeronly'] : 0
$plugin = VChamiloPlugin::create();
$thisurl = api_get_path(WEB_PLUGIN_PATH).'vchamilo/views/manage.php';
$coursePath = Virtual::getConfig('vchamilo', 'course_real_root');
$homePath = Virtual::getConfig('vchamilo', 'home_real_root');
/*$coursePath = Virtual::getConfig('vchamilo', 'course_real_root');
$homePath = Virtual::getConfig('vchamilo', 'home_real_root');*/
if ($id) {
$mode = 'update';

@ -59,12 +59,13 @@ switch ($action) {
array('where' => array("root_web = '{$n->root_web}' " => array()))
);
}
if ($todelete) {
foreach ($todelete as $fooid => $instance) {
$slug = $instance['slug'];
if (empty($slug)) {
continue;
continue;
}
// Remove all files and eventual symlinks
@ -90,6 +91,14 @@ switch ($action) {
removeDir($archivedir);
}
// Delete upload
if ($dir = Virtual::getConfig('vchamilo', 'upload_real_root')) {
$dir = $dir.'/'.$slug;
Display::addFlash(Display::return_message("Deleting $dir"));
removeDir($dir);
}
$sql = "DELETE FROM {$table} WHERE id = ".$instance['id'];
Database::query($sql);
@ -174,6 +183,7 @@ switch ($action) {
$coursePath = api_get_path(SYS_COURSE_PATH);
$homePath = api_get_path(SYS_HOME_PATH);
$archivePath = api_get_path(SYS_ARCHIVE_PATH);
$uploadPath = api_get_path(SYS_UPLOAD_PATH);
} else {
// Get Vchamilo known record.
$vchamilo = Database::select('*', 'vchamilo', array('where' => array('root_web = ?' => array($wwwroot))), 'first');
@ -181,10 +191,12 @@ switch ($action) {
$coursePath = Virtual::getConfig('vchamilo', 'course_real_root');
$homePath = Virtual::getConfig('vchamilo', 'home_real_root');
$archivePath = Virtual::getConfig('vchamilo', 'archive_real_root');
$uploadPath = Virtual::getConfig('vchamilo', 'upload_real_root');
$coursePath = $coursePath.'/'.$vchamilo->slug;
$homePath = $homePath.'/'.$vchamilo->slug;
$archivePath = $archivePath.'/'.$vchamilo->slug;
$uploadPath = $uploadPath.'/'.$vchamilo->slug;
}
$content = '';
@ -232,6 +244,9 @@ switch ($action) {
Display::addFlash(Display::return_message("Copying from '$coursePath' to '$absolute_datadir/courses' "));
copyDirTo($coursePath, $absolute_datadir.'/courses/', false);
Display::addFlash(Display::return_message("Copying from '$uploadPath' to '$absolute_datadir/upload' "));
copyDirTo($uploadPath, $absolute_datadir.'/upload/', false);
// Store original hostname and some config info for further database or filestore replacements.
$FILE = fopen($backupDir.$separator.'manifest.php', 'w');
fwrite($FILE, '<'.'?php ');
@ -242,7 +257,8 @@ switch ($action) {
// Every step was SUCCESS.
if (empty($fullautomation)) {
Display::addFlash(
Display::return_message($plugin->get_lang('successfinishedcapture'),
Display::return_message(
$plugin->get_lang('successfinishedcapture'),
'success'
)
);
@ -317,6 +333,7 @@ switch ($action) {
$coursePath = Virtual::getConfig('vchamilo', 'course_real_root');
$homePath = Virtual::getConfig('vchamilo', 'home_real_root');
$archivePath = Virtual::getConfig('vchamilo', 'archive_real_root');
//$uploadPath = Virtual::getConfig('vchamilo', 'upload_real_root');
// Get instance archive
$archivepath = api_get_path(SYS_ARCHIVE_PATH, (array)$instance);

Loading…
Cancel
Save