Fix remaining courses/ folder issues with migration from 1.9 to 1.10

Fix possible error with remaining inconsistent data in c_item_property and course_rel_user if deleting a course or user previously left inconsistent rows in these tables - refs CT#7932
1.10.x
Yannick Warnier 9 years ago
parent b8065d473d
commit d4176a460d
  1. 4
      app/Migrations/Schema/V110/Version20150603181728.php
  2. 11
      main/inc/lib/fileManage.lib.php
  3. 8
      main/install/update-files-1.9.0-1.10.0.inc.php

@ -42,6 +42,10 @@ class Version20150603181728 extends AbstractMigrationChamilo
'); ');
$this->addSql("UPDATE c_item_property SET session_id = NULL WHERE session_id = 0"); $this->addSql("UPDATE c_item_property SET session_id = NULL WHERE session_id = 0");
$this->addSql("UPDATE c_item_property SET to_group_id = NULL WHERE to_group_id = 0"); $this->addSql("UPDATE c_item_property SET to_group_id = NULL WHERE to_group_id = 0");
// Remove inconsistencies about non-existing courses
$this->addSql("DELETE FROM c_item_property WHERE c_id = 0");
// Remove inconsistencies about non-existing users
$this->addSql("DELETE FROM course_rel_user WHERE user_id = 0");
$this->addSql('ALTER TABLE c_item_property ADD CONSTRAINT FK_1D84C18191D79BD3 FOREIGN KEY (c_id) REFERENCES course (id)'); $this->addSql('ALTER TABLE c_item_property ADD CONSTRAINT FK_1D84C18191D79BD3 FOREIGN KEY (c_id) REFERENCES course (id)');
$this->addSql('ALTER TABLE c_item_property ADD CONSTRAINT FK_1D84C181330D47E9 FOREIGN KEY (to_group_id) REFERENCES c_group_info (iid)'); $this->addSql('ALTER TABLE c_item_property ADD CONSTRAINT FK_1D84C181330D47E9 FOREIGN KEY (to_group_id) REFERENCES c_group_info (iid)');
$this->addSql('ALTER TABLE c_item_property ADD CONSTRAINT FK_1D84C18129F6EE60 FOREIGN KEY (to_user_id) REFERENCES user (id)'); $this->addSql('ALTER TABLE c_item_property ADD CONSTRAINT FK_1D84C18129F6EE60 FOREIGN KEY (to_user_id) REFERENCES user (id)');

@ -210,11 +210,12 @@ function my_rename($file_path, $new_file_name) {
* @param - $source (String) - the path of file or directory to move * @param - $source (String) - the path of file or directory to move
* @param - $target (String) - the path of the new area * @param - $target (String) - the path of the new area
* @param bool $forceMove Whether to force a move or to make a copy (safer but slower) and then delete the original * @param bool $forceMove Whether to force a move or to make a copy (safer but slower) and then delete the original
* @param bool $moveContent In some cases (including migrations), we need to move the *content* and not the folder itself
* @return - bolean - true if the move succeed * @return - bolean - true if the move succeed
* bolean - false otherwise. * bolean - false otherwise.
* @see - move() uses check_name_exist() and copyDirTo() functions * @see - move() uses check_name_exist() and copyDirTo() functions
*/ */
function move($source, $target, $forceMove = false) function move($source, $target, $forceMove = false, $moveContent = false)
{ {
if (check_name_exist($source)) { if (check_name_exist($source)) {
$file_name = basename($source); $file_name = basename($source);
@ -233,7 +234,13 @@ function move($source, $target, $forceMove = false)
} elseif (is_dir($source)) { } elseif (is_dir($source)) {
/* Directory */ /* Directory */
if ($forceMove && !$isWindowsOS && $canExec) { if ($forceMove && !$isWindowsOS && $canExec) {
exec('mv $source $target'); if ($moveContent) {
$base = basename($source);
exec('mv '.$source.'/* '.$target.$base.'/');
exec('rm -rf '.$source);
} else {
exec('mv $source $target');
}
} else { } else {
copyDirTo($source, $target); copyDirTo($source, $target);
} }

@ -176,7 +176,7 @@ if (defined('SYSTEM_INSTALLATION')) {
api_get_path(SYS_CODE_PATH).'upload/users' => api_get_path(SYS_UPLOAD_PATH), api_get_path(SYS_CODE_PATH).'upload/users' => api_get_path(SYS_UPLOAD_PATH),
api_get_path(SYS_CODE_PATH).'upload/badges' => api_get_path(SYS_UPLOAD_PATH), api_get_path(SYS_CODE_PATH).'upload/badges' => api_get_path(SYS_UPLOAD_PATH),
api_get_path(SYS_PATH).'courses' => api_get_path(SYS_APP_PATH), api_get_path(SYS_PATH).'courses' => api_get_path(SYS_APP_PATH),
api_get_path(SYS_PATH).'searchdb' => api_get_path(SYS_UPLOAD_PATH).'plugins/xapian', api_get_path(SYS_PATH).'searchdb' => api_get_path(SYS_UPLOAD_PATH).'plugins/xapian/',
api_get_path(SYS_PATH).'home' => api_get_path(SYS_APP_PATH) api_get_path(SYS_PATH).'home' => api_get_path(SYS_APP_PATH)
]; ];
@ -186,8 +186,7 @@ if (defined('SYSTEM_INSTALLATION')) {
foreach ($movePathList as $origin => $destination) { foreach ($movePathList as $origin => $destination) {
if (is_dir($origin)) { if (is_dir($origin)) {
move($origin, $destination, true); move($origin, $destination, true, true);
error_log("$origin to $destination");
} }
} }
@ -205,6 +204,9 @@ if (defined('SYSTEM_INSTALLATION')) {
/** @var Symfony\Component\Finder\SplFileInfo $dir */ /** @var Symfony\Component\Finder\SplFileInfo $dir */
foreach ($dirs as $dir) { foreach ($dirs as $dir) {
$indexFile = $dir->getPath().'/index.php'; $indexFile = $dir->getPath().'/index.php';
if ($debug) {
error_log('Deleting '.$indexFile);
}
if ($fs->exists($indexFile)) { if ($fs->exists($indexFile)) {
$fs->remove($indexFile); $fs->remove($indexFile);
} }

Loading…
Cancel
Save