Files
dockerfluxodecaixapro/app/delete_affiliates_db_entries.php
T
2026-09-01 10:46:29 -03:00

108 lines
3.5 KiB
PHP
Executable File

<?php
require __DIR__ . '/../vendor/autoload.php';
use Dotenv\Dotenv;
use Illuminate\Database\Capsule\Manager as Capsule;
// Load environment variables
if (file_exists(__DIR__ . '/.env')) {
$dotenv = Dotenv::createImmutable(__DIR__);
$dotenv->load();
}
// Helper function to get environment variables
if (!function_exists('get_env')) {
function get_env(string $key, $default = null)
{
return $_ENV[$key] ?? $_SERVER[$key] ?? $default;
}
}
// Helper function to get database configuration
if (!function_exists('get_db_config')) {
function get_db_config(): array
{
return [
'driver' => get_env('DB_DRIVER', get_env('DB_CONNECTION', 'mysql')),
'host' => get_env('DB_HOST', 'localhost'),
'port' => get_env('DB_PORT', '3306'),
'database' => get_env('DB_DATABASE', 'syscms'),
'username' => get_env('DB_USERNAME', 'root'),
'password' => get_env('DB_PASSWORD', ''),
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'prefix' => '',
];
}
}
// Initialize Capsule (Eloquent)
$capsule = new Capsule;
$dbConfig = get_db_config();
$capsule->addConnection([
'driver' => $dbConfig['driver'],
'host' => $dbConfig['host'],
'port' => $dbConfig['port'],
'database' => $dbConfig['database'],
'username' => $dbConfig['username'],
'password' => $dbConfig['password'],
'charset' => $dbConfig['charset'],
'collation' => $dbConfig['collation'],
'prefix' => $dbConfig['prefix'],
]);
// Set the event dispatcher used by Eloquent models... (optional)
// use Illuminate\Events\Dispatcher;
// use Illuminate\Container\Container;
// $capsule->setEventDispatcher(new Dispatcher(new Container));
// Make this Capsule instance available globally via static methods... (optional)
$capsule->setAsGlobal();
// Setup the Eloquent ORM... (optional; unless you've used setEventDispatcher())
$capsule->bootEloquent();
echo "Conectado ao banco de dados: " . $dbConfig['database'] . " em " . $dbConfig['host'] . ":" . $dbConfig['port'] . "\n";
try {
// Remove entries from 'modules' table
echo "Removendo módulos 'affiliates' e 'affiliatesadmin' da tabela 'modules'...\n";
$deletedModules = Capsule::table('modules')
->whereIn('name', ['affiliates', 'affiliatesadmin'])
->delete();
echo "Removidos $deletedModules módulos da tabela 'modules'.\n";
// Remove entries from 'bus_modules' table
echo "Removendo módulos 'affiliates' e 'affiliatesadmin' da tabela 'bus_modules'...\n";
$deletedBusModules = Capsule::table('bus_modules')
->whereIn('module_name', ['affiliates', 'affiliatesadmin'])
->delete();
echo "Removidos $deletedBusModules módulos da tabela 'bus_modules'.\n";
// Drop affiliate tables
echo "Removendo tabelas de afiliados...\n";
$tablesToDrop = [
'affiliate_clicks',
'affiliate_banners',
'affiliate_commissions',
'affiliates',
];
foreach ($tablesToDrop as $table) {
if (Capsule::schema()->hasTable($table)) {
Capsule::schema()->drop($table);
echo "Tabela '$table' removida.\n";
} else {
echo "Tabela '$table' não existe, pulando.\n";
}
}
echo "Processo de remoção de dados e tabelas de afiliados concluído com sucesso.\n";
} catch (\Exception $e) {
echo "Erro durante a remoção: " . $e->getMessage() . "\n";
}
?>