HEX
Server: LiteSpeed
System: Linux s1049.use1.mysecurecloudhost.com 4.18.0-477.27.2.lve.el8.x86_64 #1 SMP Wed Oct 11 12:32:56 UTC 2023 x86_64
User: xedaptot (3356)
PHP: 8.3.31
Disabled: NONE
Upload Files
File: /home/xedaptot/hi.naniguide.com/app/Http/Controllers/Customer/IntegrationController.php
<?php

namespace App\Http\Controllers\Customer;

use App\Http\Controllers\Controller;
use App\Models\GoogleIntegration;
use App\Services\WordPressPluginBrandingService;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Schema;

class IntegrationController extends Controller
{
    public function __construct(
        private readonly WordPressPluginBrandingService $wordpressPluginBrandingService
    ) {
        $this->middleware('customer.access:servers.permissions.can_access_delivery_servers')->only(['index']);
    }

    public function index(Request $request)
    {
        $customer = auth('customer')->user();
        $canAccessGoogle = $customer ? (bool) $customer->groupAllows('integrations.permissions.can_access_google') : false;

        $allowedTabs = ['wordpress'];
        if ($canAccessGoogle) {
            $allowedTabs[] = 'google';
        }

        $tab = (string) $request->query('tab', $canAccessGoogle ? 'google' : 'wordpress');
        if (!in_array($tab, $allowedTabs, true)) {
            $tab = $canAccessGoogle ? 'google' : 'wordpress';
        }

        $googleIntegrations = collect();
        if ($customer && $canAccessGoogle && Schema::hasTable('google_integrations')) {
            $googleIntegrations = GoogleIntegration::query()
                ->where('customer_id', $customer->id)
                ->whereIn('service', ['sheets', 'drive'])
                ->get()
                ->keyBy('service');
        }

        $wordpressCopy = $this->wordpressPluginBrandingService->visibleCopy();

        return view('customer.integrations.index', compact('tab', 'canAccessGoogle', 'googleIntegrations', 'wordpressCopy'));
    }

    public function downloadWordpressPlugin(Request $request)
    {
        $package = $this->wordpressPluginBrandingService->packagePlugin();

        return response()->download($package['path'], $package['download_name'])->deleteFileAfterSend(true);
    }
}