diff --git a/app/Abstracts/BulkAction.php b/app/Abstracts/BulkAction.php index c89c91264..2cdaeb72e 100644 --- a/app/Abstracts/BulkAction.php +++ b/app/Abstracts/BulkAction.php @@ -123,8 +123,6 @@ abstract class BulkAction foreach ($items as $item) { $item->delete(); } - - Artisan::call('cache:clear'); } public function disableContacts($request) diff --git a/app/Jobs/Auth/CreatePermission.php b/app/Jobs/Auth/CreatePermission.php index e3c166ab5..d25030879 100644 --- a/app/Jobs/Auth/CreatePermission.php +++ b/app/Jobs/Auth/CreatePermission.php @@ -4,7 +4,6 @@ namespace App\Jobs\Auth; use App\Abstracts\Job; use App\Models\Auth\Permission; -use Artisan; class CreatePermission extends Job { @@ -29,8 +28,6 @@ class CreatePermission extends Job { $permission = Permission::create($this->request->all()); - Artisan::call('cache:clear'); - return $permission; } } diff --git a/app/Jobs/Auth/CreateRole.php b/app/Jobs/Auth/CreateRole.php index 44004d674..6ec20d1b9 100644 --- a/app/Jobs/Auth/CreateRole.php +++ b/app/Jobs/Auth/CreateRole.php @@ -4,7 +4,6 @@ namespace App\Jobs\Auth; use App\Abstracts\Job; use App\Models\Auth\Role; -use Artisan; class CreateRole extends Job { @@ -33,8 +32,6 @@ class CreateRole extends Job $role->permissions()->attach($this->request->get('permissions')); } - Artisan::call('cache:clear'); - return $role; } } diff --git a/app/Jobs/Auth/CreateUser.php b/app/Jobs/Auth/CreateUser.php index 3b8e23935..7d2edd902 100644 --- a/app/Jobs/Auth/CreateUser.php +++ b/app/Jobs/Auth/CreateUser.php @@ -52,8 +52,6 @@ class CreateUser extends Job $user->companies()->attach($this->request->get('companies')); } - Artisan::call('cache:clear'); - // Add User Dashboard if (!empty($user->companies)) { foreach ($user->companies as $company) { @@ -64,8 +62,6 @@ class CreateUser extends Job } } - Artisan::call('cache:clear'); - return $user; } } diff --git a/app/Jobs/Auth/DeletePermission.php b/app/Jobs/Auth/DeletePermission.php index b1eaff559..af007048f 100644 --- a/app/Jobs/Auth/DeletePermission.php +++ b/app/Jobs/Auth/DeletePermission.php @@ -3,7 +3,6 @@ namespace App\Jobs\Auth; use App\Abstracts\Job; -use Artisan; class DeletePermission extends Job { @@ -28,8 +27,6 @@ class DeletePermission extends Job { $this->permission->delete(); - Artisan::call('cache:clear'); - return true; } } diff --git a/app/Jobs/Auth/DeleteRole.php b/app/Jobs/Auth/DeleteRole.php index 63bf496a4..25018e2e3 100644 --- a/app/Jobs/Auth/DeleteRole.php +++ b/app/Jobs/Auth/DeleteRole.php @@ -3,7 +3,6 @@ namespace App\Jobs\Auth; use App\Abstracts\Job; -use Artisan; class DeleteRole extends Job { @@ -28,7 +27,7 @@ class DeleteRole extends Job { $this->role->delete(); - Artisan::call('cache:clear'); + $this->role->flushCache(); return true; } diff --git a/app/Jobs/Auth/DeleteUser.php b/app/Jobs/Auth/DeleteUser.php index 50db814fd..f34a0d707 100644 --- a/app/Jobs/Auth/DeleteUser.php +++ b/app/Jobs/Auth/DeleteUser.php @@ -3,7 +3,6 @@ namespace App\Jobs\Auth; use App\Abstracts\Job; -use Artisan; class DeleteUser extends Job { @@ -30,7 +29,7 @@ class DeleteUser extends Job $this->user->delete(); - Artisan::call('cache:clear'); + $this->user->flushCache(); return true; } diff --git a/app/Jobs/Auth/UpdatePermission.php b/app/Jobs/Auth/UpdatePermission.php index f77219898..632631e1f 100644 --- a/app/Jobs/Auth/UpdatePermission.php +++ b/app/Jobs/Auth/UpdatePermission.php @@ -4,7 +4,6 @@ namespace App\Jobs\Auth; use App\Abstracts\Job; use App\Models\Auth\Permission; -use Artisan; class UpdatePermission extends Job { @@ -33,8 +32,6 @@ class UpdatePermission extends Job { $this->permission->update($this->request->all()); - Artisan::call('cache:clear'); - return $this->permission; } } diff --git a/app/Jobs/Auth/UpdateRole.php b/app/Jobs/Auth/UpdateRole.php index 5475a354c..665201253 100644 --- a/app/Jobs/Auth/UpdateRole.php +++ b/app/Jobs/Auth/UpdateRole.php @@ -4,7 +4,6 @@ namespace App\Jobs\Auth; use App\Abstracts\Job; use App\Models\Auth\Role; -use Artisan; class UpdateRole extends Job { @@ -37,8 +36,6 @@ class UpdateRole extends Job $this->role->permissions()->sync($this->request->get('permissions')); } - Artisan::call('cache:clear'); - return $this->role; } } diff --git a/app/Jobs/Auth/UpdateUser.php b/app/Jobs/Auth/UpdateUser.php index e76e4b75c..3a1cd66e3 100644 --- a/app/Jobs/Auth/UpdateUser.php +++ b/app/Jobs/Auth/UpdateUser.php @@ -4,7 +4,6 @@ namespace App\Jobs\Auth; use App\Abstracts\Job; use App\Models\Auth\User; -use Artisan; class UpdateUser extends Job { @@ -58,8 +57,6 @@ class UpdateUser extends Job $this->user->companies()->sync($this->request->get('companies')); } - Artisan::call('cache:clear'); - return $this->user; } diff --git a/app/Jobs/Common/DeleteDashboard.php b/app/Jobs/Common/DeleteDashboard.php index 9fda5cca0..80a6a268e 100644 --- a/app/Jobs/Common/DeleteDashboard.php +++ b/app/Jobs/Common/DeleteDashboard.php @@ -35,8 +35,6 @@ class DeleteDashboard extends Job $this->dashboard->delete(); - Artisan::call('cache:clear'); - return true; } diff --git a/app/Traits/Modules.php b/app/Traits/Modules.php index 74e4aa072..001dfa177 100644 --- a/app/Traits/Modules.php +++ b/app/Traits/Modules.php @@ -6,7 +6,6 @@ use App\Models\Module\Module; use App\Traits\SiteApi; use App\Utilities\Console; use App\Utilities\Info; -use Artisan; use Cache; use Date; use File; @@ -35,12 +34,11 @@ trait Modules } // Get All Modules - public function getModules() + public function getModules($data = []) { - $page = isset($data['query']['page']) ? $data['query']['page'] : 1; + $key = 'apps.items.page.' . $this->getPageNumber($data); - // Get data from cache - $items = Cache::get('apps.items.page.' . $page); + $items = Cache::get($key); if (!empty($items)) { return $items; @@ -48,7 +46,7 @@ trait Modules $items = static::getResponseData('GET', 'apps/items'); - Cache::put('apps.items.page.' . $page, $items, Date::now()->addHour()); + Cache::put($key, $items, Date::now()->addHour()); return $items; } @@ -63,8 +61,9 @@ trait Modules public function getDocumentation($alias) { - // Get data from cache - $documentation = Cache::get('apps.docs.' . $alias); + $key = 'apps.docs.' . $alias; + + $documentation = Cache::get($key); if (!empty($documentation)) { return $documentation; @@ -72,17 +71,16 @@ trait Modules $documentation = static::getResponseData('GET', 'apps/docs/' . $alias); - Cache::put('apps.docs.' . $alias, $documentation, Date::now()->addHour()); + Cache::put($key, $documentation, Date::now()->addHour()); return $documentation; } public function getModuleReviews($alias, $data = []) { - $page = isset($data['query']['page']) ? $data['query']['page'] : 1; + $key = 'apps.' . $alias . '.reviews.page.'. $this->getPageNumber($data); - // Get data from cache - $reviews = Cache::get('apps.' . $alias . '.reviews.page.'. $page); + $reviews = Cache::get($key); if (!empty($reviews)) { return $reviews; @@ -90,17 +88,16 @@ trait Modules $reviews = static::getResponseData('GET', 'apps/' . $alias . '/reviews', $data); - Cache::put('apps.' . $alias . '.reviews.page.' . $page, $reviews, Date::now()->addHour()); + Cache::put($key, $reviews, Date::now()->addHour()); return $reviews; } - public function getCategories() + public function getCategories($data = []) { - $page = isset($data['query']['page']) ? $data['query']['page'] : 1; + $key = 'apps.categories.page.' . $this->getPageNumber($data); - // Get data from cache - $categories = Cache::get('apps.categories.page.' . $page); + $categories = Cache::get($key); if (!empty($categories)) { return $categories; @@ -108,17 +105,16 @@ trait Modules $categories = static::getResponseData('GET', 'apps/categories'); - Cache::put('apps.categories.page.' . $page, $categories, Date::now()->addHour()); + Cache::put($key, $categories, Date::now()->addHour()); return $categories; } public function getModulesByCategory($alias, $data = []) { - $page = isset($data['query']['page']) ? $data['query']['page'] : 1; + $key = 'apps.categories.' . $alias . '.page.' . $this->getPageNumber($data); - // Get data from cache - $category = Cache::get('apps.categories.' . $alias . '.page.' . $page); + $category = Cache::get($key); if (!empty($category)) { return $category; @@ -126,17 +122,16 @@ trait Modules $category = static::getResponseData('GET', 'apps/categories/' . $alias, $data); - Cache::put('apps.categories.' . $alias . '.page.' . $page, $category, Date::now()->addHour()); + Cache::put($key, $category, Date::now()->addHour()); return $category; } - public function getVendors() + public function getVendors($data = []) { - $page = isset($data['query']['page']) ? $data['query']['page'] : 1; + $key = 'apps.vendors.page.' . $this->getPageNumber($data); - // Get data from cache - $vendors = Cache::get('apps.vendors.page.' . $page); + $vendors = Cache::get($key); if (!empty($vendors)) { return $vendors; @@ -144,17 +139,16 @@ trait Modules $vendors = static::getResponseData('GET', 'apps/vendors'); - Cache::put('apps.vendors.page.' . $page, $vendors, Date::now()->addHour()); + Cache::put($key, $vendors, Date::now()->addHour()); return $vendors; } public function getModulesByVendor($alias, $data = []) { - $page = isset($data['query']['page']) ? $data['query']['page'] : 1; + $key = 'apps.vendors.' . $alias . '.page.' . $this->getPageNumber($data); - // Get data from cache - $vendor = Cache::get('apps.vendors.' . $alias . '.page.' . $page); + $vendor = Cache::get($key); if (!empty($vendor)) { return $vendor; @@ -162,7 +156,7 @@ trait Modules $vendor = static::getResponseData('GET', 'apps/vendors/' . $alias, $data); - Cache::put('apps.vendors.' . $alias . '.page.' . $page, $vendor, Date::now()->addHour()); + Cache::put($key, $vendor, Date::now()->addHour()); return $vendor; } @@ -172,11 +166,9 @@ trait Modules return static::getResponseData('GET', 'apps/my', $data); } - public function getInstalledModules($data = []) + public function getInstalledModules() { - $company_id = session('company_id'); - - $key = 'apps.installed.' . $company_id . '.app'; + $key = 'apps.installed.' . session('company_id'); if ($installed = Cache::get($key)) { return $installed; @@ -203,10 +195,9 @@ trait Modules public function getPreSaleModules($data = []) { - $page = isset($data['query']['page']) ? $data['query']['page'] : 1; + $key = 'apps.pre_sale.page.' . $this->getPageNumber($data); - // Get data from cache - $pre_sale = Cache::get('apps.pre_sale.page.' . $page); + $pre_sale = Cache::get($key); if (!empty($pre_sale)) { return $pre_sale; @@ -214,17 +205,16 @@ trait Modules $pre_sale = static::getResponseData('GET', 'apps/pre_sale', $data); - Cache::put('apps.pre_sale.page.' . $page, $pre_sale, Date::now()->addHour()); + Cache::put($key, $pre_sale, Date::now()->addHour()); return $pre_sale; } public function getPaidModules($data = []) { - $page = isset($data['query']['page']) ? $data['query']['page'] : 1; + $key = 'apps.paid.page.' . $this->getPageNumber($data); - // Get data from cache - $paid = Cache::get('apps.paid.page.' . $page); + $paid = Cache::get($key); if (!empty($paid)) { return $paid; @@ -232,17 +222,16 @@ trait Modules $paid = static::getResponseData('GET', 'apps/paid', $data); - Cache::put('apps.paid.page.' . $page, $paid, Date::now()->addHour()); + Cache::put($key, $paid, Date::now()->addHour()); return $paid; } public function getNewModules($data = []) { - $page = isset($data['query']['page']) ? $data['query']['page'] : 1; + $key = 'apps.new.page.' . $this->getPageNumber($data); - // Get data from cache - $new = Cache::get('apps.new.page.' . $page); + $new = Cache::get($key); if (!empty($new)) { return $new; @@ -250,17 +239,16 @@ trait Modules $new = static::getResponseData('GET', 'apps/new', $data); - Cache::put('apps.new.page.' . $page, $new, Date::now()->addHour()); + Cache::put($key, $new, Date::now()->addHour()); return $new; } public function getFreeModules($data = []) { - $page = isset($data['query']['page']) ? $data['query']['page'] : 1; + $key = 'apps.free.page.' . $this->getPageNumber($data); - // Get data from cache - $free = Cache::get('apps.free.page.' . $page); + $free = Cache::get($key); if (!empty($free)) { return $free; @@ -268,17 +256,16 @@ trait Modules $free = static::getResponseData('GET', 'apps/free', $data); - Cache::put('apps.free.page.' . $page, $free, Date::now()->addHour()); + Cache::put($key, $free, Date::now()->addHour()); return $free; } public function getFeaturedModules($data = []) { - $page = isset($data['query']['page']) ? $data['query']['page'] : 1; + $key = 'apps.featured.page.' . $this->getPageNumber($data); - // Get data from cache - $featured = Cache::get('apps.featured.page.' . $page); + $featured = Cache::get($key); if (!empty($featured)) { return $featured; @@ -286,7 +273,7 @@ trait Modules $featured = static::getResponseData('GET', 'apps/featured', $data); - Cache::put('apps.featured.page.' . $page, $featured, Date::now()->addHour()); + Cache::put($key, $featured, Date::now()->addHour()); return $featured; } @@ -447,7 +434,7 @@ trait Modules $company_id = session('company_id'); $locale = app()->getLocale(); - Cache::forget('installed.' . $company_id . '.module'); + $this->clearModulesCache(); $command = "module:install {$module->alias} {$company_id} {$locale}"; @@ -481,12 +468,9 @@ trait Modules 'version' => $module->get('version'), ]; - Artisan::call('cache:clear'); - $module->delete(); - // Cache Data clear - File::deleteDirectory(storage_path('framework/cache/data')); + $this->clearModulesCache(); return [ 'success' => true, @@ -508,7 +492,7 @@ trait Modules $module->enable(); - Artisan::call('cache:clear'); + $this->clearModulesCache(); return [ 'success' => true, @@ -530,7 +514,7 @@ trait Modules $module->disable(); - Artisan::call('cache:clear'); + $this->clearModulesCache($alias); return [ 'success' => true, @@ -564,8 +548,9 @@ trait Modules public function loadSuggestions() { - // Get data from cache - $data = Cache::get('suggestions'); + $key = 'apps.suggestions'; + + $data = Cache::get($key); if (!empty($data)) { return $data; @@ -581,15 +566,16 @@ trait Modules $data[$suggestion->path] = $suggestion; } - Cache::put('suggestions', $data, Date::now()->addHour(6)); + Cache::put($key, $data, Date::now()->addHour(6)); return $data; } public function loadNotifications() { - // Get data from cache - $data = Cache::get('notifications'); + $key = 'apps.notifications'; + + $data = Cache::get($key); if (!empty($data)) { return $data; @@ -605,15 +591,16 @@ trait Modules $data[$notification->path][] = $notification; } - Cache::put('notifications', $data, Date::now()->addHour(6)); + Cache::put($key, $data, Date::now()->addHour(6)); return $data; } public function getSuggestions($path) { - // Get data from cache - $data = Cache::get('suggestions'); + $key = 'apps.suggestions'; + + $data = Cache::get($key); if (empty($data)) { $data = $this->loadSuggestions(); @@ -628,8 +615,9 @@ trait Modules public function getNotifications($path) { - // Get data from cache - $data = Cache::get('notifications'); + $key = 'apps.notifications'; + + $data = Cache::get($key); if (empty($data)) { $data = $this->loadNotifications(); @@ -641,4 +629,24 @@ trait Modules return false; } + + public function getPageNumber($data = []) + { + if (empty($data['query']) || empty($data['query']['page'])) { + return 1; + } + + return $data['query']['page']; + } + + public function clearModulesCache() + { + if (config('module.cache.enabled')) { + Cache::forget(config('module.cache.key')); + } + + Cache::forget('apps.notifications'); + Cache::forget('apps.suggestions'); + Cache::forget('apps.installed.' . session('company_id')); + } } diff --git a/app/Utilities/Updater.php b/app/Utilities/Updater.php index f889b640f..9c1faec2c 100644 --- a/app/Utilities/Updater.php +++ b/app/Utilities/Updater.php @@ -8,7 +8,7 @@ use App\Events\Install\UpdateUnzipped; use App\Models\Module\Module; use App\Utilities\Console; use App\Traits\SiteApi; -use Artisan; +use App\Traits\Modules; use Cache; use Date; use File; @@ -17,11 +17,13 @@ use ZipArchive; class Updater { - use SiteApi; + use Modules, SiteApi; public static function clear() { - Artisan::call('cache:clear'); + Cache::forget('updates'); + Cache::forget('versions'); + $this->clearModulesCache(); return true; } diff --git a/modules/OfflinePayments/Http/Controllers/Settings.php b/modules/OfflinePayments/Http/Controllers/Settings.php index 806c0f333..21ba06d48 100644 --- a/modules/OfflinePayments/Http/Controllers/Settings.php +++ b/modules/OfflinePayments/Http/Controllers/Settings.php @@ -3,8 +3,8 @@ namespace Modules\OfflinePayments\Http\Controllers; use App\Abstracts\Http\Controller; -use Artisan; use Illuminate\Http\Response; +use Illuminate\Support\Facades\Cache; use Modules\OfflinePayments\Http\Requests\Setting as Request; use Modules\OfflinePayments\Http\Requests\SettingGet as GRequest; use Modules\OfflinePayments\Http\Requests\SettingDelete as DRequest; @@ -68,7 +68,9 @@ class Settings extends Controller setting()->save(); - Artisan::call('cache:clear'); + if (config('setting.cache.enabled')) { + Cache::forget(setting()->getCacheKey()); + } $response = [ 'status' => null, @@ -152,7 +154,9 @@ class Settings extends Controller setting()->save(); - Artisan::call('cache:clear'); + if (config('setting.cache.enabled')) { + Cache::forget(setting()->getCacheKey()); + } $message = trans('messages.success.deleted', ['type' => $remove['name']]); diff --git a/overrides/akaunting/module/Commands/DeleteCommand.php b/overrides/akaunting/module/Commands/DeleteCommand.php index a7868b456..64b51c517 100644 --- a/overrides/akaunting/module/Commands/DeleteCommand.php +++ b/overrides/akaunting/module/Commands/DeleteCommand.php @@ -4,8 +4,8 @@ namespace Akaunting\Module\Commands; use App\Models\Module\Module; use App\Models\Module\ModuleHistory; -use Artisan; use Illuminate\Console\Command; +use Illuminate\Support\Facades\Cache; use Illuminate\Support\Str; use Symfony\Component\Console\Input\InputArgument; @@ -62,7 +62,9 @@ class DeleteCommand extends Command // Trigger event event(new \App\Events\Module\Deleted($alias, $company_id)); - Artisan::call('cache:clear'); + if (config('module.cache.enabled')) { + Cache::forget(config('module.cache.key')); + } $this->info("Module [{$alias}] deleted."); } diff --git a/overrides/akaunting/module/Commands/InstallCommand.php b/overrides/akaunting/module/Commands/InstallCommand.php index ffcc216fb..870f3a5b5 100644 --- a/overrides/akaunting/module/Commands/InstallCommand.php +++ b/overrides/akaunting/module/Commands/InstallCommand.php @@ -6,6 +6,7 @@ use App\Models\Module\Module; use App\Models\Module\ModuleHistory; use App\Traits\Permissions; use Illuminate\Console\Command; +use Illuminate\Support\Facades\Cache; use Illuminate\Support\Str; use Symfony\Component\Console\Input\InputArgument; @@ -60,7 +61,9 @@ class InstallCommand extends Command 'description' => trans('modules.installed', ['module' => $alias]), ]); - $this->call('cache:clear'); + if (config('module.cache.enabled')) { + Cache::forget(config('module.cache.key')); + } // Disable model cache during installation config(['laravel-model-caching.enabled' => false]);