@@ -83,33 +83,34 @@ function theme_photo_update_settings_images($settingname) {
83
83
// This is the component name the setting is stored in.
84
84
$ component = 'theme_photo ' ;
85
85
86
+
86
87
// This is the value of the admin setting which is the filename of the uploaded file.
87
88
$ filename = get_config ($ component , $ settingname );
88
89
// We extract the file extension because we want to preserve it.
89
90
$ extension = substr ($ filename , strrpos ($ filename , '. ' ) + 1 );
90
91
91
92
// This is the path in the moodle internal file system.
92
93
$ fullpath = "/ {$ syscontext ->id }/ {$ component }/ {$ settingname }/0 {$ filename }" ;
94
+
95
+ // This location matches the searched for location in theme_config::resolve_image_location.
96
+ $ pathname = $ CFG ->dataroot . '/pix_plugins/theme/photo/ ' . $ settingname . '. ' . $ extension ;
97
+
98
+ // This pattern matches any previous files with maybe different file extensions.
99
+ $ pathpattern = $ CFG ->dataroot . '/pix_plugins/theme/photo/ ' . $ settingname . '.* ' ;
100
+
101
+ // Make sure this dir exists.
102
+ @mkdir ($ CFG ->dataroot . '/pix_plugins/theme/photo/ ' , $ CFG ->directorypermissions , true );
103
+
104
+ // Delete any existing files for this setting.
105
+ foreach (glob ($ pathpattern ) as $ filename ) {
106
+ @unlink ($ filename );
107
+ }
108
+
93
109
// Get an instance of the moodle file storage.
94
110
$ fs = get_file_storage ();
95
111
// This is an efficient way to get a file if we know the exact path.
96
112
if ($ file = $ fs ->get_file_by_hash (sha1 ($ fullpath ))) {
97
113
// We got the stored file - copy it to dataroot.
98
- // This location matches the searched for location in theme_config::resolve_image_location.
99
- $ pathname = $ CFG ->dataroot . '/pix_plugins/theme/photo/ ' . $ settingname . '. ' . $ extension ;
100
-
101
- // This pattern matches any previous files with maybe different file extensions.
102
- $ pathpattern = $ CFG ->dataroot . '/pix_plugins/theme/photo/ ' . $ settingname . '.* ' ;
103
-
104
- // Make sure this dir exists.
105
- @mkdir ($ CFG ->dataroot . '/pix_plugins/theme/photo/ ' , $ CFG ->directorypermissions , true );
106
-
107
- // Delete any existing files for this setting.
108
- foreach (glob ($ pathpattern ) as $ filename ) {
109
- @unlink ($ filename );
110
- }
111
-
112
- // Copy the current file to this location.
113
114
$ file ->copy_content_to ($ pathname );
114
115
}
115
116
0 commit comments