@@ 1569-1691 (lines=123) @@ | ||
1566 | /** |
|
1567 | * Restore announcements |
|
1568 | */ |
|
1569 | public function restore_announcements($sessionId = 0) |
|
1570 | { |
|
1571 | if ($this->course->has_resources(RESOURCE_ANNOUNCEMENT)) { |
|
1572 | $sessionId = intval($sessionId); |
|
1573 | $table = Database :: get_course_table(TABLE_ANNOUNCEMENT); |
|
1574 | $resources = $this->course->resources; |
|
1575 | foreach ($resources[RESOURCE_ANNOUNCEMENT] as $id => $announcement) { |
|
1576 | ||
1577 | // check resources inside html from ckeditor tool and copy correct urls into recipient course |
|
1578 | $announcement->content = DocumentManager::replace_urls_inside_content_html_from_copy_course( |
|
1579 | $announcement->content, |
|
1580 | $this->course->code, |
|
1581 | $this->course->destination_path, |
|
1582 | $this->course->backup_path, |
|
1583 | $this->course->info['path'] |
|
1584 | ); |
|
1585 | ||
1586 | $params = [ |
|
1587 | 'c_id' => $this->destination_course_id, |
|
1588 | 'title' => self::DBUTF8($announcement->title), |
|
1589 | 'content' => self::DBUTF8($announcement->content), |
|
1590 | 'end_date' => $announcement->date, |
|
1591 | 'display_order' => $announcement->display_order, |
|
1592 | 'email_sent' => $announcement->email_sent, |
|
1593 | 'session_id' => $sessionId, |
|
1594 | ]; |
|
1595 | ||
1596 | $new_announcement_id = Database::insert($table, $params); |
|
1597 | ||
1598 | if ($new_announcement_id) { |
|
1599 | $sql = "UPDATE $table SET id = iid WHERE iid = $new_announcement_id"; |
|
1600 | Database::query($sql); |
|
1601 | ||
1602 | if (!isset($this->course->resources[RESOURCE_ANNOUNCEMENT][$id])) { |
|
1603 | $this->course->resources[RESOURCE_ANNOUNCEMENT][$id] = new stdClass(); |
|
1604 | } |
|
1605 | $this->course->resources[RESOURCE_ANNOUNCEMENT][$id]->destination_id = $new_announcement_id; |
|
1606 | } |
|
1607 | ||
1608 | $origin_path = $this->course->backup_path.'/upload/announcements/'; |
|
1609 | $destination_path = api_get_path(SYS_COURSE_PATH).$this->course->destination_path.'/upload/announcements/'; |
|
1610 | ||
1611 | // Copy announcement attachment file |
|
1612 | if (!empty($this->course->orig)) { |
|
1613 | ||
1614 | $table_attachment = Database::get_course_table(TABLE_ANNOUNCEMENT_ATTACHMENT); |
|
1615 | $sql = 'SELECT path, comment, size, filename |
|
1616 | FROM '.$table_attachment.' |
|
1617 | WHERE |
|
1618 | c_id = '.$this->destination_course_id.' AND |
|
1619 | announcement_id = '.$id; |
|
1620 | $attachment_event = Database::query($sql); |
|
1621 | $attachment_event = Database::fetch_object($attachment_event); |
|
1622 | ||
1623 | if (file_exists($origin_path.$attachment_event->path) && |
|
1624 | !is_dir($origin_path.$attachment_event->path) |
|
1625 | ) { |
|
1626 | $new_filename = uniqid(''); //ass seen in the add_agenda_attachment_file() function in agenda.inc.php |
|
1627 | $copy_result = copy( |
|
1628 | $origin_path.$attachment_event->path, |
|
1629 | $destination_path.$new_filename |
|
1630 | ); |
|
1631 | ||
1632 | if ($copy_result) { |
|
1633 | $table_attachment = Database :: get_course_table(TABLE_ANNOUNCEMENT_ATTACHMENT); |
|
1634 | ||
1635 | $params = [ |
|
1636 | 'c_id' => $this->destination_course_id, |
|
1637 | 'path' => self::DBUTF8($new_filename), |
|
1638 | 'comment' => self::DBUTF8($attachment_event->comment), |
|
1639 | 'size' => $attachment_event->size, |
|
1640 | 'filename' => $attachment_event->filename, |
|
1641 | 'announcement_id' => $new_announcement_id, |
|
1642 | ]; |
|
1643 | ||
1644 | $attachmentId = Database::insert($table_attachment, $params); |
|
1645 | ||
1646 | if ($attachmentId) { |
|
1647 | $sql = "UPDATE $table_attachment SET id = iid WHERE iid = $attachmentId"; |
|
1648 | Database::query($sql); |
|
1649 | } |
|
1650 | } |
|
1651 | } |
|
1652 | } else { |
|
1653 | // get the info of the file |
|
1654 | if (!empty($announcement->attachment_path) && |
|
1655 | is_file($origin_path.$announcement->attachment_path) && |
|
1656 | is_readable($origin_path.$announcement->attachment_path) |
|
1657 | ) { |
|
1658 | $new_filename = uniqid(''); //ass seen in the add_agenda_attachment_file() function in agenda.inc.php |
|
1659 | $copy_result = copy($origin_path.$announcement->attachment_path, $destination_path.$new_filename); |
|
1660 | ||
1661 | if ($copy_result) { |
|
1662 | $table_attachment = Database :: get_course_table(TABLE_ANNOUNCEMENT_ATTACHMENT); |
|
1663 | /*$sql = "INSERT INTO ".$table_attachment." SET |
|
1664 | c_id = ".$this->destination_course_id." , |
|
1665 | path = '".self::DBUTF8escapestring($new_filename)."', |
|
1666 | comment = '".self::DBUTF8escapestring($announcement->attachment_comment)."', |
|
1667 | size = '".$announcement->attachment_size."', filename = '".$announcement->attachment_filename."', |
|
1668 | announcement_id = '".$new_announcement_id."' "; |
|
1669 | Database::query($sql);*/ |
|
1670 | ||
1671 | $params = [ |
|
1672 | 'c_id' => $this->destination_course_id, |
|
1673 | 'path' => self::DBUTF8($new_filename), |
|
1674 | 'comment' => self::DBUTF8($announcement->attachment_comment), |
|
1675 | 'size' => $announcement->attachment_size, |
|
1676 | 'filename' => $announcement->attachment_filename, |
|
1677 | 'announcement_id' => $new_announcement_id, |
|
1678 | ]; |
|
1679 | ||
1680 | $attachmentId = Database::insert($table_attachment, $params); |
|
1681 | ||
1682 | if ($attachmentId) { |
|
1683 | $sql = "UPDATE $table_attachment SET id = iid WHERE iid = $attachmentId"; |
|
1684 | Database::query($sql); |
|
1685 | } |
|
1686 | } |
|
1687 | } |
|
1688 | } |
|
1689 | } |
|
1690 | } |
|
1691 | } |
|
1692 | ||
1693 | /** |
|
1694 | * Restore Quiz |
|
@@ 1411-1517 (lines=107) @@ | ||
1408 | /** |
|
1409 | * Restore events |
|
1410 | */ |
|
1411 | public function restore_events($sessionId = 0) |
|
1412 | { |
|
1413 | if ($this->course->has_resources(RESOURCE_EVENT)) { |
|
1414 | $sessionId = intval($sessionId); |
|
1415 | $table = Database :: get_course_table(TABLE_AGENDA); |
|
1416 | $resources = $this->course->resources; |
|
1417 | foreach ($resources[RESOURCE_EVENT] as $id => $event) { |
|
1418 | // check resources inside html from ckeditor tool and copy correct urls into recipient course |
|
1419 | $event->content = DocumentManager::replace_urls_inside_content_html_from_copy_course( |
|
1420 | $event->content, |
|
1421 | $this->course->code, |
|
1422 | $this->course->destination_path, |
|
1423 | $this->course->backup_path, |
|
1424 | $this->course->info['path'] |
|
1425 | ); |
|
1426 | ||
1427 | $params = [ |
|
1428 | 'c_id' => $this->destination_course_id, |
|
1429 | 'title' => self::DBUTF8($event->title), |
|
1430 | 'content' => self::DBUTF8($event->content), |
|
1431 | 'all_day' => $event->all_day, |
|
1432 | 'start_date' => $event->start_date, |
|
1433 | 'end_date' => $event->end_date, |
|
1434 | 'session_id' => $sessionId, |
|
1435 | ]; |
|
1436 | $new_event_id = Database::insert($table, $params); |
|
1437 | ||
1438 | if ($new_event_id) { |
|
1439 | $sql = "UPDATE $table SET id = iid WHERE iid = $new_event_id"; |
|
1440 | Database::query($sql); |
|
1441 | ||
1442 | if (!isset($this->course->resources[RESOURCE_EVENT][$id])) { |
|
1443 | $this->course->resources[RESOURCE_EVENT][$id] = new stdClass(); |
|
1444 | } |
|
1445 | ||
1446 | $this->course->resources[RESOURCE_EVENT][$id]->destination_id = $new_event_id; |
|
1447 | } |
|
1448 | ||
1449 | // Copy event attachment |
|
1450 | ||
1451 | $origin_path = $this->course->backup_path.'/upload/calendar/'; |
|
1452 | $destination_path = api_get_path(SYS_COURSE_PATH).$this->course->destination_path.'/upload/calendar/'; |
|
1453 | ||
1454 | if (!empty($this->course->orig)) { |
|
1455 | ||
1456 | $table_attachment = Database :: get_course_table(TABLE_AGENDA_ATTACHMENT); |
|
1457 | $sql = 'SELECT path, comment, size, filename |
|
1458 | FROM '.$table_attachment.' |
|
1459 | WHERE c_id = '.$this->destination_course_id.' AND agenda_id = '.$id; |
|
1460 | $attachment_event = Database::query($sql); |
|
1461 | $attachment_event = Database::fetch_object($attachment_event); |
|
1462 | ||
1463 | if (file_exists($origin_path.$attachment_event->path) && |
|
1464 | !is_dir($origin_path.$attachment_event->path) |
|
1465 | ) { |
|
1466 | $new_filename = uniqid(''); //ass seen in the add_agenda_attachment_file() function in agenda.inc.php |
|
1467 | $copy_result = copy($origin_path.$attachment_event->path, $destination_path.$new_filename); |
|
1468 | //$copy_result = true; |
|
1469 | if ($copy_result) { |
|
1470 | $table_attachment = Database :: get_course_table(TABLE_AGENDA_ATTACHMENT); |
|
1471 | ||
1472 | $params = [ |
|
1473 | 'c_id' => $this->destination_course_id, |
|
1474 | 'path' => self::DBUTF8($new_filename), |
|
1475 | 'comment' => self::DBUTF8($attachment_event->comment), |
|
1476 | 'size' => $attachment_event->size, |
|
1477 | 'filename' => $attachment_event->filename, |
|
1478 | 'agenda_id' => $new_event_id, |
|
1479 | ]; |
|
1480 | $id = Database::insert($table_attachment, $params); |
|
1481 | if ($id) { |
|
1482 | $sql = "UPDATE $table_attachment SET id = iid WHERE iid = $id"; |
|
1483 | Database::query($sql); |
|
1484 | } |
|
1485 | } |
|
1486 | } |
|
1487 | } else { |
|
1488 | // get the info of the file |
|
1489 | if (!empty($event->attachment_path) && |
|
1490 | is_file($origin_path.$event->attachment_path) && |
|
1491 | is_readable($origin_path.$event->attachment_path) |
|
1492 | ) { |
|
1493 | $new_filename = uniqid(''); //ass seen in the add_agenda_attachment_file() function in agenda.inc.php |
|
1494 | $copy_result = copy($origin_path.$event->attachment_path, $destination_path.$new_filename); |
|
1495 | if ($copy_result) { |
|
1496 | $table_attachment = Database :: get_course_table(TABLE_AGENDA_ATTACHMENT); |
|
1497 | ||
1498 | $params = [ |
|
1499 | 'c_id' => $this->destination_course_id, |
|
1500 | 'path' => self::DBUTF8($new_filename), |
|
1501 | 'comment' => self::DBUTF8($event->attachment_comment), |
|
1502 | 'size' => $event->size, |
|
1503 | 'filename' => $event->filename, |
|
1504 | 'agenda_id' => $new_event_id, |
|
1505 | ]; |
|
1506 | $id = Database::insert($table_attachment, $params); |
|
1507 | ||
1508 | if ($id) { |
|
1509 | $sql = "UPDATE $table_attachment SET id = iid WHERE iid = $id"; |
|
1510 | Database::query($sql); |
|
1511 | } |
|
1512 | } |
|
1513 | } |
|
1514 | } |
|
1515 | } |
|
1516 | } |
|
1517 | } |
|
1518 | ||
1519 | /** |
|
1520 | * Restore course-description |