Proyectos de Subversion Moodle

Rev

Rev 1 | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 1 Rev 1441
Línea 534... Línea 534...
534
    /** @var string instance name. */
534
    /** @var string instance name. */
535
    public $name;
535
    public $name;
536
    /** @var bool true if the super construct is called, otherwise false. */
536
    /** @var bool true if the super construct is called, otherwise false. */
537
    public $super_called;
537
    public $super_called;
Línea -... Línea 538...
-
 
538
 
-
 
539
    /** @var array List of file ids currently being synced, to avoid endless recursion */
-
 
540
    protected static $syncfileids = [];
538
 
541
 
539
    /**
542
    /**
540
     * Constructor
543
     * Constructor
541
     *
544
     *
542
     * @param int $repositoryid repository instance id
545
     * @param int $repositoryid repository instance id
Línea 1219... Línea 1222...
1219
     * @param int $lifetime Number of seconds before the file should expire from caches (null means $CFG->filelifetime)
1222
     * @param int $lifetime Number of seconds before the file should expire from caches (null means $CFG->filelifetime)
1220
     * @param int $filter 0 (default)=no filtering, 1=all files, 2=html files only
1223
     * @param int $filter 0 (default)=no filtering, 1=all files, 2=html files only
1221
     * @param bool $forcedownload If true (default false), forces download of file rather than view in browser/plugin
1224
     * @param bool $forcedownload If true (default false), forces download of file rather than view in browser/plugin
1222
     * @param array $options additional options affecting the file serving
1225
     * @param array $options additional options affecting the file serving
1223
     */
1226
     */
1224
    public function send_file($storedfile, $lifetime=null , $filter=0, $forcedownload=false, array $options = null) {
1227
    public function send_file($storedfile, $lifetime=null , $filter=0, $forcedownload=false, ?array $options = null) {
1225
        if ($this->has_moodle_files()) {
1228
        if ($this->has_moodle_files()) {
1226
            $fs = get_file_storage();
1229
            $fs = get_file_storage();
1227
            $params = file_storage::unpack_reference($storedfile->get_reference(), true);
1230
            $params = file_storage::unpack_reference($storedfile->get_reference(), true);
1228
            $srcfile = null;
1231
            $srcfile = null;
1229
            if (is_array($params)) {
1232
            if (is_array($params)) {
Línea 1783... Línea 1786...
1783
            }
1786
            }
1784
        }
1787
        }
1785
    }
1788
    }
Línea 1786... Línea 1789...
1786
 
1789
 
1787
    /**
-
 
1788
     * Return size of a file in bytes.
-
 
1789
     *
-
 
1790
     * @param string $source encoded and serialized data of file
-
 
1791
     * @return int file size in bytes
-
 
1792
     *
1790
    /**
1793
     * @deprecated since Moodle 4.3
1791
     * @deprecated since Moodle 4.3
1794
     */
-
 
1795
    public function get_file_size($source) {
1792
     */
1796
        debugging(__FUNCTION__ . ' is deprecated, please do not use it any more', DEBUG_DEVELOPER);
-
 
1797
 
1793
    #[\core\attribute\deprecated(null, reason: 'No longer used', since: '4.3', mdl: 'MDL-50272', final: true)]
1798
        $browser    = get_file_browser();
-
 
1799
        $params     = unserialize(base64_decode($source));
1794
    public function get_file_size() {
1800
        $contextid  = clean_param($params['contextid'], PARAM_INT);
-
 
1801
        $fileitemid = clean_param($params['itemid'], PARAM_INT);
-
 
1802
        $filename   = clean_param($params['filename'], PARAM_FILE);
-
 
1803
        $filepath   = clean_param($params['filepath'], PARAM_PATH);
-
 
1804
        $filearea   = clean_param($params['filearea'], PARAM_AREA);
-
 
1805
        $component  = clean_param($params['component'], PARAM_COMPONENT);
-
 
1806
        $context    = context::instance_by_id($contextid);
-
 
1807
        $file_info  = $browser->get_file_info($context, $component, $filearea, $fileitemid, $filepath, $filename);
-
 
1808
        if (!empty($file_info)) {
-
 
1809
            $filesize = $file_info->get_filesize();
-
 
1810
        } else {
-
 
1811
            $filesize = null;
-
 
1812
        }
-
 
1813
        return $filesize;
1795
        \core\deprecation::emit_deprecation([self::class, __FUNCTION__]);
Línea 1814... Línea 1796...
1814
    }
1796
    }
1815
 
1797
 
1816
    /**
1798
    /**
Línea 2696... Línea 2678...
2696
            $storedfile->delete();
2678
            $storedfile->delete();
2697
        }
2679
        }
2698
    }
2680
    }
Línea 2699... Línea 2681...
2699
 
2681
 
2700
    /**
-
 
2701
     * Function repository::reset_caches() is deprecated, cache is handled by MUC now.
-
 
2702
     * @deprecated since Moodle 2.6 MDL-42016 - please do not use this function any more.
-
 
2703
     */
-
 
2704
    public static function reset_caches() {
-
 
2705
        throw new coding_exception('Function repository::reset_caches() can not be used any more, cache is handled by MUC now.');
-
 
2706
    }
-
 
2707
 
-
 
2708
    /**
-
 
2709
     * Function repository::sync_external_file() is deprecated. Use repository::sync_reference instead
-
 
2710
     *
-
 
2711
     * @deprecated since Moodle 2.6 MDL-42016 - please do not use this function any more.
-
 
2712
     * @see repository::sync_reference()
-
 
2713
     */
-
 
2714
    public static function sync_external_file($file, $resetsynchistory = false) {
-
 
2715
        throw new coding_exception('Function repository::sync_external_file() can not be used any more. ' .
-
 
2716
            'Use repository::sync_reference instead.');
-
 
2717
    }
-
 
2718
 
-
 
2719
    /**
2682
    /**
2720
     * Performs synchronisation of an external file if the previous one has expired.
2683
     * Performs synchronisation of an external file if the previous one has expired.
2721
     *
2684
     *
2722
     * This function must be implemented for external repositories supporting
2685
     * This function must be implemented for external repositories supporting
2723
     * FILE_REFERENCE, it is called for existing aliases when their filesize,
2686
     * FILE_REFERENCE, it is called for existing aliases when their filesize,
Línea 2757... Línea 2720...
2757
            // References to local files need to be synchronised only once.
2720
            // References to local files need to be synchronised only once.
2758
            // Later they will be synchronised automatically when the source is changed.
2721
            // Later they will be synchronised automatically when the source is changed.
2759
            if ($file->get_referencelastsync()) {
2722
            if ($file->get_referencelastsync()) {
2760
                return false;
2723
                return false;
2761
            }
2724
            }
-
 
2725
 
-
 
2726
            if (in_array($file->get_id(), self::$syncfileids)) {
-
 
2727
                throw new \coding_exception('File references itself: ' . $file->get_id());
-
 
2728
            }
-
 
2729
            try {
-
 
2730
                array_push(self::$syncfileids, $file->get_id());
-
 
2731
 
2762
            $fs = get_file_storage();
2732
                $fs = get_file_storage();
2763
            $params = file_storage::unpack_reference($file->get_reference(), true);
2733
                $params = file_storage::unpack_reference($file->get_reference(), true);
2764
            if (!is_array($params) || !($storedfile = $fs->get_file($params['contextid'],
2734
                if (!is_array($params) || !($storedfile = $fs->get_file($params['contextid'],
2765
                    $params['component'], $params['filearea'], $params['itemid'], $params['filepath'],
2735
                        $params['component'], $params['filearea'], $params['itemid'], $params['filepath'],
2766
                    $params['filename']))) {
2736
                        $params['filename']))) {
2767
                $file->set_missingsource();
2737
                    $file->set_missingsource();
2768
            } else {
2738
                } else {
-
 
2739
                    $file->set_synchronized(
-
 
2740
                        $storedfile->get_contenthash(),
-
 
2741
                        $storedfile->get_filesize(),
-
 
2742
                        0,
2769
                $file->set_synchronized($storedfile->get_contenthash(), $storedfile->get_filesize(), 0, $storedfile->get_timemodified());
2743
                        $storedfile->get_timemodified(),
-
 
2744
                    );
-
 
2745
                }
-
 
2746
            } finally {
-
 
2747
                array_pop(self::$syncfileids);
2770
            }
2748
            }
2771
            return true;
2749
            return true;
2772
        }
2750
        }
Línea 2773... Línea 2751...
2773
 
2751