setPath($cacheDir); CacheManager::setDefaultConfig($config); return CacheManager::getInstance('files'); } /** * @return bool */ function isCacheEnabled() { $query = " SELECT id, meta_key, meta_value FROM `".ACPT_Lite_DB::prefixedTableName(ACPT_Lite_DB::TABLE_SETTINGS)."` WHERE meta_key = %s "; $res = ACPT_Lite_DB::getResults($query, ['enable_cache']); if(empty($res) or $res[0]->meta_value == 1){ return true; } return false; } /** * Init the DB */ function initDB() { /** * Inject DB Cache */ try { if(isCacheEnabled()){ ACPT_Lite_DB::injectCache(cacheInstance()); } } catch (\Exception $exception){ // do nothing } } /** * This function get the old version from the filemtime value of main plugin file * * @param int $old_version * * @return string */ function oldPluginVersion($old_version) { if(empty($old_version) or $old_version == 0){ return null; } if(!is_numeric($old_version)){ return null; } $date = date("Y-m-d", $old_version); if($date == "1970-01-01"){ return null; } $config = Ini::read(__DIR__.'/../config.ini'); $pluginVersions = $config['versions']; return (isset(array_flip($pluginVersions)[$date])) ? array_flip($pluginVersions)[$date] : null; } /** * Check for plugin upgrades */ function checkForPluginUpgrades() { try { $old_version = (!empty(get_option('acpt_lite_current_version'))) ? get_option('acpt_lite_current_version') : get_option('acpt_lite_version', 0); $current_version = (!empty(get_option('acpt_lite_current_version'))) ? ACPT_LITE_PLUGIN_VERSION : filemtime(__FILE__); if ($old_version != $current_version) { ACPT_Lite_DB::flushCache(); ACPT_Lite_DB::createSchema(ACPT_LITE_PLUGIN_VERSION, get_option('acpt_lite_current_version') ?? oldPluginVersion($old_version)); ACPT_Lite_DB::sync(); update_option('acpt_lite_version', $current_version, false); update_option('acpt_lite_current_version', ACPT_LITE_PLUGIN_VERSION, false); } } catch (\Exception $exception){ // do nothing } }