@@ -753,30 +753,46 @@ public function editTheme(request $request)
753753
754754 if (!empty ($ zipfile ) && Auth::user ()->role == 'admin ' ) {
755755
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 " );
757759
758760 $ 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 );
761763 $ zip ->close ();
762- unlink (base_path () . ' /themes/temp.zip ' );
764+ unlink ($ tmpPath );
763765
764766 // Removes version numbers from folder.
765767
766- $ folder = base_path ('themes ' );
767768 $ regex = '/[0-9.-]/ ' ;
768- $ files = scandir ($ folder );
769+ $ files = scandir ($ themesPath );
769770 $ files = array_diff ($ files , array ('. ' , '.. ' ));
770771
771772 foreach ($ files as $ file ) {
773+
772774 $ 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+
773785 if (preg_match ($ regex , $ basename )) {
786+
774787 $ 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+
778792 }
793+
779794 }
795+
780796 }
781797
782798
0 commit comments