Index: /changelog
===================================================================
--- /changelog	(revision 8451)
+++ /changelog	(revision 8452)
@@ -639,3 +639,4 @@
 - Bugfix: Bestellungen mit Teil - Gtuscheinen kÃ¶nnen jetzt mit PayPal zurÃŒckerstattet werden
 - Bugfix: Steuersatz 0 fÃŒhrt nicht zu einem Fehler beim schreiben der Rechnung
-- Bugfix: Warenkorb Button im Widget bei Option "Lightbox Meldung"
+- Bugfix: DB Udpdate nach Plugin Update wird ausgefÃŒhrt
+- Feature: Update Log um zukÃŒnftige Probleme beim Update zu erkennen
Index: /controller/wpsg_AdminController.class.php
===================================================================
--- /controller/wpsg_AdminController.class.php	(revision 8451)
+++ /controller/wpsg_AdminController.class.php	(revision 8452)
@@ -2708,6 +2708,5 @@
 		 * Installiert ein Modul
 		 */
-		public function installModul($modul_key)
-		{
+		public function installModul($modul_key) {
 
 			global $wp_filesystem;
@@ -2717,4 +2716,7 @@
 				
 			$wpsg_update_data = wpsg_get_update_data();
+			
+			if (!isset($wpsg_update_data['modulinfo'][$modul_key]['download_url'])) throw new \wpsg\ModulURLNotFoundException(wpsg_translate(__('URL zu Modul #1# unbekannt', 'wpsg'), $modul_key));
+			
 			$url = $wpsg_update_data['modulinfo'][$modul_key]['download_url'];
 			 
@@ -2723,29 +2725,24 @@
 			$bOK = @copy($url, $temp_name);
 			
-			if (!$bOK)
-			{
+			if (!$bOK) {
 			
 				$bOK = @file_put_contents($temp_name, $this->shop->get_url_content($url));
 			
-				if (!$bOK)
-				{
+				if (!$bOK) {
 						
 					// Pfad finden fÃŒr das Wordpress Filesystem
-					if ($GLOBALS['wpsg_sc']->isMultiBlog())
-						$ftp_path = WP_CONTENT_DIR.'/'.WPSG_MB_UPLOADS.'/wpsg/wpsg_temp/';
-					else
-						$ftp_path = WP_CONTENT_DIR.'/uploads/wpsg/wpsg_temp/';
+					if ($GLOBALS['wpsg_sc']->isMultiBlog()) $ftp_path = WP_CONTENT_DIR.'/'.WPSG_MB_UPLOADS.'/wpsg/wpsg_temp/';
+					else $ftp_path = WP_CONTENT_DIR.'/uploads/wpsg/wpsg_temp/';
 								
-						$ftp_path = trailingslashit($wp_filesystem->find_folder($ftp_path)).preg_replace('/(.*)\/wpsg_temp\//', '', $temp_name);
-								
-						$bOK = $wp_filesystem->put_contents($ftp_path, $this->shop->get_url_content($url), FS_CHMOD_FILE);
-								
-						if (!$bOK)
-						{
-									
-							$this->shop->addBackendError(wpsg_translate(__('Modul (#1#) konnte nicht kopiert werden!', 'wpsg'), $modul_key));
-							return false;
-			
-						}
+					$ftp_path = trailingslashit($wp_filesystem->find_folder($ftp_path)).preg_replace('/(.*)\/wpsg_temp\//', '', $temp_name);
+					
+					$bOK = $wp_filesystem->put_contents($ftp_path, $this->shop->get_url_content($url), FS_CHMOD_FILE);
+					
+					if (!$bOK) {
+						
+						$this->shop->addBackendError(wpsg_translate(__('Modul (#1#) konnte nicht kopiert werden!', 'wpsg'), $modul_key));
+						return false;
+		
+					}
 								
 				}
@@ -2755,21 +2752,16 @@
 			$zip = new ZipArchive();
 			 
-			if ($zip->open($temp_name) === true)
-			{
-			
-				try
-				{
+			if ($zip->open($temp_name) === true) {
+			
+				try {
 															
 					$bOK = @$zip->extractTo(realpath(WPSG_PATH.'/../'));
 					$zip->close();
 			
-					if ($bOK === false)
-					{
+					if ($bOK === false) {
 			
 						throw new Exception();
 							
-					}
-					else
-					{
+					} else {
 			
 						return true;
@@ -2777,7 +2769,5 @@
 					}
 			
-				}
-				catch (Exception $e)
-				{
+				} catch (Exception $e) {
 						
 					// Es ist ein Fehler aufgetreten, jetzt versuche ich die Datei mit dem Wordpress Filesystem zu entpacken
@@ -2788,12 +2778,10 @@
 					$bOK = unzip_file($temp_name, $ftp_path);
 						
-					if ($bOK !== true)
-					{
+					if ($bOK !== true) {
 			
 						$strError = '';
 			
 						// Hier ist immer noch ein Fehler aufgetreten
-						foreach ((array)$bOK->errors as $e)
-						{
+						foreach ((array)$bOK->errors as $e) {
 								
 							$strError .= $e[0].' ';
@@ -2803,7 +2791,5 @@
 						$this->shop->addBackendError(wpsg_translate(__('Fehler beim Entpacken: #1#', 'wpsg'), $strError)); return false;
 			
-					}
-					else
-					{
+					} else {
 			
 						return true;
@@ -2813,7 +2799,5 @@
 				}
 			
-			}
-			else
-			{
+			} else {
 			
 				$this->shop->addBackendError(__('Datei konnte nicht ÃŒbertragen werden.', 'wpsg')); return false;
Index: /controller/wpsg_ShopController.class.php
===================================================================
--- /controller/wpsg_ShopController.class.php	(revision 8451)
+++ /controller/wpsg_ShopController.class.php	(revision 8452)
@@ -801,5 +801,5 @@
 			$this->checkDefault('wpsg_shopdata_2_country', '1');
 			$this->checkDefault('wpsg_shopdata_eu_country', '1');
-            
+   					
         } // public function init()
 
Index: /lib/filter_functions.inc.php
===================================================================
--- /lib/filter_functions.inc.php	(revision 8451)
+++ /lib/filter_functions.inc.php	(revision 8452)
@@ -38,5 +38,5 @@
         $wpsg_update_data = wpsg_get_update_data();
     
-        if (is_object($wpsg_update_data['updateData'])) {
+        if ($wpsg_update_data !== null && is_object($wpsg_update_data['updateData'])) {
     
             if (property_exists($wpsg_update_data['updateData'], 'banner')) {
@@ -506,4 +506,6 @@
 
         }
+		
+		if (!is_array($wpsg_update_data)) $wpsg_update_data = null;
         
         return $wpsg_update_data;
@@ -692,4 +694,27 @@
     function wpsg_pre_install($test) {
     
+		$update_log = [];
+		
+		try {
+		
+			$update_log = json_decode(wpsg_ShopController::getShop()->get_option('wpsg_update_log'), true);
+			if (!is_array($update_log)) $update_log = [];
+			
+		} catch (\Throwable $e) {  }
+		
+		$update = [
+			'time' => \wp_date('d.m.Y H:i:s'),
+			'pre' => [
+				'version' => WPSG_VERSION,
+				'installed_modules' => array_keys(wpsg_ShopController::getShop()->arModule)
+			],
+			'after' => [
+			
+			]
+		];
+		
+		$update_log[sizeof($update_log)] = $update;
+		wpsg_ShopController::getShop()->update_option('wpsg_update_log', json_encode($update_log));
+		
         global $wp_filesystem;
     
@@ -699,8 +724,6 @@
     
         // TemporÃ€res Verzeichnis 
-        if ($GLOBALS['wpsg_sc']->isMultiBlog())
-            $path = WP_CONTENT_DIR.'/'.WPSG_MB_UPLOADS.'/wpsg/wpsg_temp/update_temp/';
-        else
-            $path = WP_CONTENT_DIR.'/uploads/wpsg_temp/update_temp/';
+        if ($GLOBALS['wpsg_sc']->isMultiBlog()) $path = WP_CONTENT_DIR.'/'.WPSG_MB_UPLOADS.'/wpsg/wpsg_temp/update_temp/';
+        else $path = WP_CONTENT_DIR.'/uploads/wpsg_temp/update_temp/';
     
         if (!file_exists($path)) wpsg_mkdir($path);
@@ -708,6 +731,5 @@
     
         // Translation rauskopieren
-        if (file_exists(WPSG_PATH.'/lib/translation.phtml'))
-        {
+        if (file_exists(WPSG_PATH.'/lib/translation.phtml')) {
     
             if (!file_exists($path.'/lib/')) wpsg_mkdir($path.'/lib/');
@@ -720,6 +742,5 @@
     
         // Ãbersetzungsdatei rauskopieren
-        if (file_exists(WPSG_PATH.'/lang/'))
-        {
+        if (file_exists(WPSG_PATH.'/lang/')) {
     
             @wpsg_mkdir($path.'/lang/', 0777, true);
@@ -731,6 +752,5 @@
     
         // User_views kopieren
-        if (file_exists(WPSG_PATH.'/user_views/'))
-        {
+        if (file_exists(WPSG_PATH.'/user_views/')) {
     
             @wpsg_mkdir($path.'/user_views/', 0777, true);
@@ -746,6 +766,5 @@
      * Funktion, die nach dem Update aufgerufen wird um die Dateien wieder an die richtige Stelle zu schieben
      */
-    function wpsg_post_install()
-    {
+    function wpsg_post_install($response, $hook_extra, $result) {
     
         global $wp_filesystem;
@@ -753,13 +772,14 @@
         $wpsg_update_data = wpsg_get_update_data(false, true);
     
-        if ($_REQUEST['plugin'] != WPSG_FOLDERNAME.'/wpshopgermany.php') return;
+		$plugin = isset($hook_extra['plugin'])?$hook_extra['plugin']:'';
+		
+        // if ($_REQUEST['plugin'] != WPSG_FOLDERNAME.'/wpshopgermany.php') return;
+        if ($plugin != WPSG_FOLDERNAME.'/wpshopgermany.php') return;
     
         if (!isset($_REQUEST['_ajax_nonce'])) echo __('Kopiere Shop zurÃŒck ...', 'wpsg').'<br />';
     
         // TemporÃ€res Verzeichnis 
-        if ($GLOBALS['wpsg_sc']->isMultiBlog())
-            $path = WP_CONTENT_DIR.'/'.WPSG_MB_UPLOADS.'/wpsg/wpsg_temp/update_temp/';
-        else
-            $path = WP_CONTENT_DIR.'/uploads/wpsg_temp/update_temp/';
+        if ($GLOBALS['wpsg_sc']->isMultiBlog()) $path = WP_CONTENT_DIR.'/'.WPSG_MB_UPLOADS.'/wpsg/wpsg_temp/update_temp/';
+        else $path = WP_CONTENT_DIR.'/uploads/wpsg_temp/update_temp/';
     
         //if (file_exists($path.'/lib/translation.phtml')) copy($path.'/lib/translation.phtml', WPSG_PATH.'/lib/translation.phtml');
@@ -767,6 +787,5 @@
         //if (file_exists($path.'/lang/')) wpsg_copy($path.'/lang/', WPSG_PATH.'/lang/');
     
-        if (file_exists($path.'/lib/translation.phtml'))
-        {
+        if (file_exists($path.'/lib/translation.phtml')) {
     
             $source_file = $path.'lib/translation.phtml';
@@ -777,6 +796,5 @@
         }
     
-        if (file_exists($path.'/user_views/'))
-        {
+        if (file_exists($path.'/user_views/')) {
     
             $source_file = $path.'user_views';
@@ -787,6 +805,5 @@
         }
     
-        if (file_exists($path.'/lang'))
-        {
+        if (file_exists($path.'/lang')) {
     
             $source_file = $path.'lang';
@@ -822,8 +839,45 @@
         $GLOBALS['wpsg_sc']->loadModule();
     
-        wpsg_install($wpsg_update_data['updateData']->new_version);
-
-        unset($_SESSION['wpsg']['backendMessage']);
+		$arUpdateData = json_decode(json_encode($wpsg_update_data), true);
+		
+        wpsg_install($arUpdateData['version']);
+		
+		// Nach dem Update wenn der neue Code lÃ€uft
+		$update_log = [];
+		
+		try { $update_log = json_decode(wpsg_ShopController::getShop()->get_option('wpsg_update_log'), true); }
+		catch (\Throwable $e) { }
+		
+		$wpsg_last_update_index = sizeof($update_log) - 1;
+		
+		if (isset($update_log[$wpsg_last_update_index])) {
+			
+			$arUpdateData = json_decode(json_encode($wpsg_update_data), true);
+			
+			$update_log[$wpsg_last_update_index]['after'] = [
+				'version' => $arUpdateData['version']??'n.A.',
+				'wpsg_update_data' => json_decode(json_encode($wpsg_update_data), true)
+			];
+			
+			// Zur Sicherheit hier nochmal die vorher installierten Module versuchen nachzuinstallieren
+			foreach ($update_log[$wpsg_last_update_index]['pre']['installed_modules'] as $modul_key) {
+			
+				try {
+				
+					$AC->installModul($modul_key);
+					
+				} catch (\wpsg\ModulURLNotFoundException $e) { /* Das kann passieren da nicht alles Kaufmodule sind */ }
+				
+			}
+			
+		}
+		
+		wpsg_ShopController::getShop()->update_option('wpsg_update_log', json_encode($update_log));
+		
+		unset($_SESSION['wpsg']['backendMessage']);
         unset($_SESSION['wpsg']['backendError']);
+        unset($_SESSION['sanitization_err_fields']);
+		
+		update_user_meta(get_current_user_id(), 'wpsg_backendError', []);
 
     } // function wpsg_post_install()
Index: /lib/functions.inc.php
===================================================================
--- /lib/functions.inc.php	(revision 8451)
+++ /lib/functions.inc.php	(revision 8452)
@@ -534,4 +534,6 @@
 		
 		$bReturn = false;
+		
+		if ($type === null) $type = WPSG_SANITIZE_TEXTFIELD;
 		
 		if (wpsg_isSizedArray($param['allow']) && in_array($val, $param['allow'])) return true;		
Index: /lib/wpsg_exceptionhandler.class.php
===================================================================
--- /lib/wpsg_exceptionhandler.class.php	(revision 8451)
+++ /lib/wpsg_exceptionhandler.class.php	(revision 8452)
@@ -9,4 +9,6 @@
     namespace wpsg;
     
+	class ModulURLNotFoundException extends \Exception {}
+	
     abstract class Exceptionhandler {
 
@@ -63,5 +65,5 @@
 	            else file_put_contents($log_file, $strLogText);
 
-			}
+			} else throw $ex;
 
             if ($break) die(wpsg_debug($typeLabel.": ".$msg."\r\n".($backtrace??''), true));
Index: /views/admin/ueber.phtml
===================================================================
--- /views/admin/ueber.phtml	(revision 8451)
+++ /views/admin/ueber.phtml	(revision 8452)
@@ -24,4 +24,7 @@
 				<a class="list-group-item <?php echo ((isset($_REQUEST['subaction']) && $_REQUEST['subaction'] == 'systemlog')?'active':''); ?>"
 				href="<?php echo wpsg_url(WPSG_URL_WP.'wp-admin/admin.php?page=wpsg-Admin&action=ueber&subaction=systemlog'); ?>"><?php echo __('Fehlerprotokoll', 'wpsg'); ?></a>
+			
+				<a class="list-group-item <?php echo ((isset($_REQUEST['subaction']) && $_REQUEST['subaction'] == 'updatelog')?'active':''); ?>"
+				href="<?php echo wpsg_url(WPSG_URL_WP.'wp-admin/admin.php?page=wpsg-Admin&action=ueber&subaction=updatelog'); ?>"><?php echo __('Updateprotokoll', 'wpsg'); ?></a>
 
 		</div>
@@ -120,4 +123,29 @@
 
 <?php echo wpsg_drawForm_AdminboxEnd(); ?>
+<?php } ?>
+
+<?php if (isset($_REQUEST['subaction']) && $_REQUEST['subaction'] == 'updatelog') {
+	
+	try { $wpsg_update_log = json_decode($this->get_option('wpsg_update_log'), true); } catch (\Throwable $e) { $wpsg_update_log = []; }
+		
+	?>
+
+	<?php foreach ($wpsg_update_log as $log_index => $log) { ?>
+	
+		<?php echo wpsg_drawForm_AdminboxStart(
+			wpsg_translate(__('Update vom #1# : #2# -> #3#', 'wpsg'), ($log['time']??''), ($log['pre']['version']??''), ($log['after']['version']??'')),
+			'wpsg_update_log_'.$log_index,
+			[
+				'collapsed' => true,
+				'collapsable' => true
+			]
+		); ?>
+	
+		<pre><?php print_r($log); ?></pre>
+
+		<?php echo wpsg_drawForm_AdminboxEnd(); ?>
+	
+	<?php } ?>
+	
 <?php } ?>
 
Index: /wpshopgermany.php
===================================================================
--- /wpshopgermany.php	(revision 8451)
+++ /wpshopgermany.php	(revision 8452)
@@ -264,5 +264,5 @@
 
 	add_filter('upgrader_pre_install', 'wpsg_pre_install', 10, 2);
-	add_filter('upgrader_post_install', 'wpsg_post_install', 10, 2);
+	add_filter('upgrader_post_install', 'wpsg_post_install', 10, 3);
 
 	if (is_admin()) {
