Bläddra i källkod

N.1052 After a setup or MTP, the datamodel is not taken into account... until the web server gets restarted or the APC cache (user data) gets reset.

git-svn-id: http://svn.code.sf.net/p/itop/code/trunk@4922 a333f486-631f-4898-b8df-5754b55c2be0
romainq 7 år sedan
förälder
incheckning
fca1a7df06
2 ändrade filer med 25 tillägg och 11 borttagningar
  1. 24 1
      core/apc-compat.php
  2. 1 10
      core/metamodel.class.php

+ 24 - 1
core/apc-compat.php

@@ -1,5 +1,5 @@
 <?php
-// Copyright (C) 2016 Combodo SARL
+// Copyright (C) 2016-2017 Combodo SARL
 //
 //   This file is part of iTop.
 //
@@ -67,3 +67,26 @@ if (!function_exists('apc_store') && function_exists('apcu_store'))
 		return apcu_store($key, $var, $ttl);
 	}
 }
+
+/**
+ * Returns user cache info... beware of the format of the returned structure that may vary (See usages)
+ * @return array
+ */
+function apc_cache_info_compat()
+{
+	if (!function_exists('apc_cache_info')) return array();
+
+	$oFunction = new ReflectionFunction('apc_cache_info');
+	if ($oFunction->getNumberOfParameters() != 2)
+	{
+		// Beware: APCu behaves slightly differently from APC !!
+		// Worse: the compatibility layer integrated into APC differs from apcu-bc (testing the number of parameters is a must)
+		// In CLI mode (PHP > 7) apc_cache_info returns null and outputs an error message.
+		$aCacheUserData = @apc_cache_info();
+	}
+	else
+	{
+		$aCacheUserData = @apc_cache_info('user');
+	}
+	return $aCacheUserData;
+}

+ 1 - 10
core/metamodel.class.php

@@ -5226,21 +5226,12 @@ abstract class MetaModel
 
 	public static function GetCacheEntries($sEnvironment = null)
 	{
-		if (!function_exists('apc_cache_info')) return array();
 		if (is_null($sEnvironment))
 		{
 			$sEnvironment = MetaModel::GetEnvironmentId();
 		}
 		$aEntries = array();
-		if (extension_loaded('apcu'))
-		{
-			// Beware: APCu behaves slightly differently from APC !!
-			$aCacheUserData = @apc_cache_info();
-		}
-		else
-		{
-			$aCacheUserData = @apc_cache_info('user');
-		}
+		$aCacheUserData = apc_cache_info_compat();
 		if (is_array($aCacheUserData) && isset($aCacheUserData['cache_list']))
 		{ 
 			$sPrefix = 'itop-'.$sEnvironment.'-';