@@ -288,20 +288,21 @@ public function is_file_readable_externally_by_hash($contenthash) {
288288 * @return int
289289 */
290290 public function get_object_location_from_hash ($ contenthash ) {
291- $ localreadable = $ this -> is_file_readable_locally_by_hash ( $ contenthash );
292- $ externalreadable = $ this -> is_file_readable_externally_by_hash ( $ contenthash );
293-
294- if ($ localreadable && $ externalreadable ) {
295- return OBJECT_LOCATION_DUPLICATED ;
296- } else if ( $ localreadable && ! $ externalreadable ) {
297- return OBJECT_LOCATION_LOCAL ;
298- } else if (! $ localreadable && $ externalreadable ) {
299- return OBJECT_LOCATION_EXTERNAL ;
300- } else {
301- // Object is not anywhere - we toggle an error state in the DB.
302- manager:: update_object_by_hash ( $ contenthash , OBJECT_LOCATION_ERROR );
303- return OBJECT_LOCATION_ERROR ;
291+ // The mdl_files bit is always set because this function is only called
292+ // for objects known to be referenced in the files table.
293+ $ location = OBJECT_LOCATION_IN_MDL_FILES ;
294+ if ($ this -> is_file_readable_locally_by_hash ( $ contenthash ) ) {
295+ $ location |= OBJECT_LOCATION_IN_FILEDIR ;
296+ }
297+ if ( $ this -> is_file_readable_externally_by_hash ( $ contenthash )) {
298+ $ location |= OBJECT_LOCATION_IN_REMOTE ;
299+ }
300+
301+ if ( $ location === OBJECT_LOCATION_MISSING ) {
302+ // Object exists in mdl_files but is not anywhere physically — record missing state.
303+ manager:: update_object_by_hash ( $ contenthash , OBJECT_LOCATION_MISSING ) ;
304304 }
305+ return $ location ;
305306 }
306307
307308 /**
@@ -465,7 +466,7 @@ public function readfile(\stored_file $file) {
465466 $ this ->logger ->log_object_read ('readfile ' , $ path , $ file ->get_filesize ());
466467
467468 if ($ success === false ) {
468- manager::update_object_by_hash ($ file ->get_contenthash (), OBJECT_LOCATION_ERROR );
469+ manager::update_object_by_hash ($ file ->get_contenthash (), OBJECT_LOCATION_MISSING );
469470 }
470471 }
471472 }
@@ -495,7 +496,7 @@ public function get_content(\stored_file $file) {
495496 $ this ->logger ->log_object_read ('file_get_contents ' , $ path , $ file ->get_filesize ());
496497
497498 if (!$ contents ) {
498- manager::update_object_by_hash ($ file ->get_contenthash (), OBJECT_LOCATION_ERROR );
499+ manager::update_object_by_hash ($ file ->get_contenthash (), OBJECT_LOCATION_MISSING );
499500 }
500501
501502 return $ contents ;
@@ -589,7 +590,7 @@ public function get_content_file_handle(\stored_file $file, $type = \stored_file
589590 $ this ->logger ->log_object_read ('get_file_handle_for_path ' , $ path , $ file ->get_filesize ());
590591
591592 if (!$ filehandle ) {
592- manager::update_object_by_hash ($ file ->get_contenthash (), OBJECT_LOCATION_ERROR );
593+ manager::update_object_by_hash ($ file ->get_contenthash (), OBJECT_LOCATION_MISSING );
593594 }
594595
595596 return $ filehandle ;
@@ -720,6 +721,7 @@ public function delete_object_from_hash($contenthash) {
720721 $ this ->delete_external_file_from_hash ($ contenthash );
721722 break ;
722723
724+ case OBJECT_LOCATION_MISSING :
723725 case OBJECT_LOCATION_ERROR :
724726 default :
725727 return ;
0 commit comments