|
@@ -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
|
|
|
+ );
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -663,12 +679,19 @@ class Virtual
|
|
|
if ($return === 'head') {
|
|
|
$htmlHeadXtra[] = $str;
|
|
|
}
|
|
|
+
|
|
|
if ($return) {
|
|
|
return $str;
|
|
|
}
|
|
|
echo $str;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * @param $file
|
|
|
+ * @param $component
|
|
|
+ * @param bool $return
|
|
|
+ * @return string
|
|
|
+ */
|
|
|
public static function requireCss($file, $component, $return = false)
|
|
|
{
|
|
|
global $_configuration, $htmlHeadXtra;
|
|
@@ -722,16 +745,20 @@ class Virtual
|
|
|
|
|
|
global $virtualChamilo;
|
|
|
if (!isset($virtualChamilo)) {
|
|
|
- api_not_allowed(true, 'You have to edit the configuration.php. Please check the readme file.');
|
|
|
+ api_not_allowed(
|
|
|
+ true,
|
|
|
+ 'You have to edit the configuration.php. Please check the readme file.'
|
|
|
+ );
|
|
|
}
|
|
|
|
|
|
$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 +769,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')
|
|
|
);
|
|
|
}
|
|
|
}
|
|
@@ -787,7 +822,6 @@ class Virtual
|
|
|
);
|
|
|
|
|
|
if ($getManager) {
|
|
|
-
|
|
|
return $manager;
|
|
|
}
|
|
|
|
|
@@ -857,6 +891,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 +907,6 @@ class Virtual
|
|
|
}
|
|
|
|
|
|
// or we continue with physical creation
|
|
|
-
|
|
|
self::createDirsFromSlug($slug);
|
|
|
|
|
|
if (!$template) {
|
|
@@ -890,8 +929,10 @@ class Virtual
|
|
|
|
|
|
$sitename = Database::escape_string($data->sitename);
|
|
|
$institution = Database::escape_string($data->institution);
|
|
|
+
|
|
|
$sqls[] = "UPDATE {$settingstable} SET selected_value = '{$sitename}'
|
|
|
WHERE variable = 'siteName' AND category = 'Platform' ";
|
|
|
+
|
|
|
$sqls[] = "UPDATE {$settingstable} SET selected_value = '{$institution}'
|
|
|
WHERE variable = 'institution' AND category = 'Platform' ";
|
|
|
|
|
@@ -930,9 +971,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;
|
|
@@ -953,7 +996,6 @@ class Virtual
|
|
|
$data->lastcron = 0;
|
|
|
$data->lastcrongap = 0;
|
|
|
$data->croncount = 0;
|
|
|
- $template = '';
|
|
|
|
|
|
$mainDatabase = api_get_configuration_value('main_database');
|
|
|
|
|
@@ -962,7 +1004,7 @@ class Virtual
|
|
|
Display::return_message('You cannot use the same database as the chamilo master', 'error')
|
|
|
);
|
|
|
|
|
|
- return ;
|
|
|
+ return false;
|
|
|
}
|
|
|
|
|
|
self::ctrace('Registering: '.$data->root_web);
|
|
@@ -978,19 +1020,14 @@ 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');
|
|
|
-
|
|
|
$institution = $settings['Institution'];
|
|
|
$siteName = $settings['siteName'];
|
|
|
-
|
|
|
$newDatabase->sitename = $siteName;
|
|
|
$newDatabase->institution = $institution;
|
|
|
-
|
|
|
$slug = $newDatabase->slug = $data->slug = Virtual::getSlugFromUrl($data->root_web);
|
|
|
$id = Database::insert($table, (array) $newDatabase);
|
|
|
}
|
|
@@ -999,6 +1036,10 @@ class Virtual
|
|
|
throw new Exception('Was not registered');
|
|
|
}
|
|
|
|
|
|
+ if (empty($slug)) {
|
|
|
+ throw new Exception('Slug is empty');
|
|
|
+ }
|
|
|
+
|
|
|
self::createDirsFromSlug($slug);
|
|
|
self::ctrace("Create database");
|
|
|
Virtual::createDatabase($newDatabase);
|
|
@@ -1032,23 +1073,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 +1112,6 @@ class Virtual
|
|
|
$settings = $statement->fetchAll();
|
|
|
$settings = array_column($settings, 'selected_value', 'variable');
|
|
|
$settings['data_base'];
|
|
|
-
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -1095,53 +1144,30 @@ 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");
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
- */
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -1181,7 +1207,6 @@ class Virtual
|
|
|
$currentVersion = implode('.', [$versionParts[0], $versionParts[1], '0']);
|
|
|
|
|
|
if (version_compare($version, $currentVersion, '<')) {
|
|
|
-
|
|
|
return $version;
|
|
|
}
|
|
|
|