@@ -753,30 +753,46 @@ public function editTheme(request $request)
753
753
754
754
if (!empty ($ zipfile ) && Auth::user ()->role == 'admin ' ) {
755
755
756
- $ zipfile ->move (base_path ('/themes ' ), "temp.zip " );
756
+ $ themesPath = base_path ('themes ' );
757
+ $ tmpPath = base_path () . '/themes/temp.zip ' ;
758
+ $ zipfile ->move ($ themesPath , "temp.zip " );
757
759
758
760
$ zip = new ZipArchive ;
759
- $ zip ->open (base_path () . ' /themes/temp.zip ' );
760
- $ zip ->extractTo (base_path () . ' /themes ' );
761
+ $ zip ->open ($ tmpPath );
762
+ $ zip ->extractTo ($ themesPath );
761
763
$ zip ->close ();
762
- unlink (base_path () . ' /themes/temp.zip ' );
764
+ unlink ($ tmpPath );
763
765
764
766
// Removes version numbers from folder.
765
767
766
- $ folder = base_path ('themes ' );
767
768
$ regex = '/[0-9.-]/ ' ;
768
- $ files = scandir ($ folder );
769
+ $ files = scandir ($ themesPath );
769
770
$ files = array_diff ($ files , array ('. ' , '.. ' ));
770
771
771
772
foreach ($ files as $ file ) {
773
+
772
774
$ basename = basename ($ file );
775
+ $ filePath = $ themesPath . '/ ' . $ basename ;
776
+
777
+ if (!is_dir ($ filePath )) {
778
+
779
+ try {
780
+ File::delete ($ filePath );
781
+ } catch (exception $ e ) {}
782
+
783
+ }
784
+
773
785
if (preg_match ($ regex , $ basename )) {
786
+
774
787
$ newBasename = preg_replace ($ regex , '' , $ basename );
775
- $ newPath = $ folder . '/ ' . $ newBasename ;
776
- File::copyDirectory ($ file , $ newPath );
777
- File::deleteDirectory ($ file );
788
+ $ newPath = $ themesPath . '/ ' . $ newBasename ;
789
+ File::copyDirectory ($ filePath , $ newPath );
790
+ File::deleteDirectory ($ filePath );
791
+
778
792
}
793
+
779
794
}
795
+
780
796
}
781
797
782
798
0 commit comments