Code Duplication    Length = 29-30 lines in 2 locations

src/Chamilo/CourseBundle/Component/CourseCopy/CourseRestorer.php 2 locations

@@ 1636-1664 (lines=29) @@
1633
                    $attachment_event = Database::query($sql);
1634
                    $attachment_event = Database::fetch_object($attachment_event);
1635
1636
                    if (file_exists($origin_path.$attachment_event->path) &&
1637
                        !is_dir($origin_path.$attachment_event->path)
1638
                    ) {
1639
                        $new_filename = uniqid(''); //ass seen in the add_agenda_attachment_file() function in agenda.inc.php
1640
                        $copy_result = copy(
1641
                            $origin_path.$attachment_event->path,
1642
                            $destination_path.$new_filename
1643
                        );
1644
1645
                        if ($copy_result) {
1646
                            $table_attachment = Database::get_course_table(TABLE_ANNOUNCEMENT_ATTACHMENT);
1647
1648
                            $params = [
1649
                                'c_id' => $this->destination_course_id,
1650
                                'path' => self::DBUTF8($new_filename),
1651
                                'comment' => self::DBUTF8($attachment_event->comment),
1652
                                'size' => $attachment_event->size,
1653
                                'filename' => $attachment_event->filename,
1654
                                'announcement_id' => $new_announcement_id,
1655
                            ];
1656
1657
                            $attachmentId = Database::insert($table_attachment, $params);
1658
1659
                            if ($attachmentId) {
1660
                                $sql = "UPDATE $table_attachment SET id = iid WHERE iid = $attachmentId";
1661
                                Database::query($sql);
1662
                            }
1663
                        }
1664
                    }
1665
                } else {
1666
                    // get the info of the file
1667
                    if (!empty($announcement->attachment_path) &&
@@ 1665-1694 (lines=30) @@
1662
                            }
1663
                        }
1664
                    }
1665
                } else {
1666
                    // get the info of the file
1667
                    if (!empty($announcement->attachment_path) &&
1668
                        is_file($origin_path.$announcement->attachment_path) &&
1669
                        is_readable($origin_path.$announcement->attachment_path)
1670
                    ) {
1671
                        $new_filename = uniqid(''); //ass seen in the add_agenda_attachment_file() function in agenda.inc.php
1672
                        $copy_result = copy($origin_path.$announcement->attachment_path, $destination_path.$new_filename);
1673
1674
                        if ($copy_result) {
1675
                            $table_attachment = Database::get_course_table(TABLE_ANNOUNCEMENT_ATTACHMENT);
1676
1677
                            $params = [
1678
                                'c_id' => $this->destination_course_id,
1679
                                'path' => self::DBUTF8($new_filename),
1680
                                'comment' => self::DBUTF8($announcement->attachment_comment),
1681
                                'size' => $announcement->attachment_size,
1682
                                'filename' => $announcement->attachment_filename,
1683
                                'announcement_id' => $new_announcement_id,
1684
                            ];
1685
1686
                            $attachmentId = Database::insert($table_attachment, $params);
1687
1688
                            if ($attachmentId) {
1689
                                $sql = "UPDATE $table_attachment SET id = iid WHERE iid = $attachmentId";
1690
                                Database::query($sql);
1691
                            }
1692
                        }
1693
                    }
1694
                }
1695
            }
1696
        }
1697
    }