/** * Since we are creating test db on the fly, we need switch to the Test DB */ protected function switchDB() { if ($this->isVerbose()) { $this->info(sprintf("Switching to %s ...", $this->test_db_name)); } Config::set('database.connections.' . $this->default_db_type . '.database', $this->test_db_name); DB::reconnect(); }
/** * Handle the event. * * @param EmailChangeRequested $event * @return void */ public function handle(EmailChangeRequested $event) { DB::reconnect(); $user = $event->user; $data = ['email' => $user->email, 'name' => $user->name, 'token' => $user->requestEmailToken()]; Mail::queueOn('deployer-low', 'emails.change_email', $data, function (Message $message) use($user) { $message->to($user->email, $user->name)->subject(Lang::get('emails.confirm_email')); }); }
/** * check database type. If SQLite, then create the database file. */ private function sqlite() { if (DB::connection() instanceof SQLiteConnection) { $database = DB::connection()->getDatabaseName(); if (!file_exists($database)) { touch($database); DB::reconnect(Config::get('database.default')); } } }
/** * Sets the database information, migrates and seeds the database * * @param Request $request * @param InstallHelper $helper * @return redirect */ public function postDatabase(Request $request, InstallHelper $helper) { foreach (['host' => 'DB_HOST', 'port' => 'DB_PORT', 'database' => 'DB_DATABASE', 'username' => 'DB_USERNAME', 'password' => 'DB_PASSWORD'] as $key => $envKey) { $helper->setEnvVariable($envKey, $request->input($key)); config()->set('database.connections.' . env('DB_CONNECTION') . '.' . $key, $request->input($key)); } DB::reconnect(env('DB_CONNECTION')); Artisan::call('migrate'); Artisan::call('db:seed'); return redirect()->route('install-user'); }
/** * Migrate & Seed the test DB */ public function setUp() { parent::setUp(); if (!$this->use_database) { return; } if ($this->test_db) { Config::set('database.connections.' . DB::getName() . '.database', $this->test_db); DB::reconnect(); } $this->pdo = DB::connection()->getPdo(); $this->pdo->beginTransaction(); }
/** * Execute the command. * * @return void */ public function handle() { DB::reconnect(); $project = $this->deployment->project; $this->deployment->started_at = date('Y-m-d H:i:s'); $this->deployment->status = Deployment::DEPLOYING; $this->deployment->save(); $project->status = Project::DEPLOYING; $project->save(); $this->private_key = tempnam(storage_path() . '/app/', 'sshkey'); file_put_contents($this->private_key, $project->private_key); try { // If the build has been manually triggered update the git information from the remote repository if ($this->deployment->commit === Deployment::LOADING) { $this->updateRepoInfo(); } foreach ($this->deployment->steps as $step) { $this->runStep($step); } $this->deployment->status = Deployment::COMPLETED; $project->status = Project::FINISHED; } catch (\Exception $error) { $this->deployment->status = Deployment::FAILED; $project->status = Project::FAILED; if ($error->getMessage() === 'Cancelled') { $this->deployment->status = Deployment::ABORTED; } $this->cancelPendingSteps($this->deployment->steps); if (isset($step)) { // Cleanup the release if it has not been activated if ($step->stage <= Stage::DO_ACTIVATE) { $this->cleanupDeployment(); } else { $this->deployment->status = Deployment::COMPLETED_WITH_ERRORS; $project->status = Project::FINISHED; } } } $this->deployment->finished_at = date('Y-m-d H:i:s'); $this->deployment->save(); $project->last_run = date('Y-m-d H:i:s'); $project->save(); // Notify user or others the deployment has been finished event(new DeployFinished($project, $this->deployment)); unlink($this->private_key); }
/** * Creates the application. * * @return \Illuminate\Foundation\Application */ public function createApplication() { $app = (require __DIR__ . '/../bootstrap/app.php'); /** @var \Illuminate\Foundation\Application $app */ /** @var \Illuminate\Contracts\Console\Kernel $kernel */ $kernel = $app->make(\Illuminate\Contracts\Console\Kernel::class); /** @noinspection PhpUndefinedMethodInspection */ $kernel->bootstrap(); if (DB::connection() instanceof \Illuminate\Database\SQLiteConnection) { $database = DB::connection()->getDatabaseName(); if (file_exists($database)) { unlink($database); } touch($database); DB::reconnect(config('database.default')); } $kernel->call('migrate'); return $app; }
/** * Execute the command. * * @return void */ public function handle() { DB::reconnect(); foreach ($this->links as $link) { $has_error = false; try { $response = Request::get($link->url)->send(); $link->last_status = $response->hasErrors(); $link->save(); $has_error = $response->hasErrors(); } catch (ConnectionErrorException $error) { $has_error = true; } $link->last_status = $has_error; $link->save(); if ($has_error) { foreach ($link->project->notifications as $notification) { $this->dispatch(new Notify($notification, $link->notificationPayload())); } } } }
/** * Execute the command. * * @return void */ public function handle() { DB::reconnect(); $this->server->status = Server::TESTING; $this->server->save(); $key = tempnam(storage_path() . '/app/', 'sshkey'); file_put_contents($key, $this->server->project->private_key); try { $command = $this->sshCommand($this->server, $key, 'ls'); $process = new Process($command); $process->setTimeout(null); $process->run(); if (!$process->isSuccessful()) { $this->server->status = Server::FAILED; } else { $this->server->status = Server::SUCCESSFUL; } } catch (\Exception $error) { $this->server->status = Server::FAILED; } $this->server->save(); unlink($key); }
/** * Run the migrations. * * The up() method will change the default value of TIMESTAMP * and DATETIME columns to NULL. * * Yes. This is the shittest migration ever. * * @return void */ public function up() { // Heads up that this is a heavy migration. print 'Running migration to fix strict mode date constraints. ' . 'This may take some time to complete.' . PHP_EOL; // Temporarily disable the string SQL mode for this session. config(['database.connections.mysql.strict' => false]); config(['database.connections.mysql.modes' => null]); // Reconnect the database connection after we changed the mode. DB::reconnect(); // Define the columns that are up for change. $timestamp_columns = ['created_at', 'updated_at']; // Define the tables and their columns that should be updated $timestamp_tables_and_columns = ['account_account_statuses' => $timestamp_columns, 'account_api_key_info_characters' => $timestamp_columns, 'account_api_key_infos' => $timestamp_columns, 'api_token_logs' => $timestamp_columns, 'api_tokens' => $timestamp_columns, 'character_account_balances' => $timestamp_columns, 'character_asset_list_contents' => $timestamp_columns, 'character_asset_lists' => $timestamp_columns, 'character_bookmarks' => $timestamp_columns, 'character_character_sheet_corporation_titles' => $timestamp_columns, 'character_character_sheet_implants' => $timestamp_columns, 'character_character_sheet_jump_clone_implants' => $timestamp_columns, 'character_character_sheet_jump_clones' => $timestamp_columns, 'character_character_sheet_skills' => $timestamp_columns, 'character_character_sheets' => $timestamp_columns, 'character_chat_channel_infos' => $timestamp_columns, 'character_chat_channel_members' => $timestamp_columns, 'character_chat_channels' => $timestamp_columns, 'character_contact_list_alliance_labels' => $timestamp_columns, 'character_contact_list_alliances' => $timestamp_columns, 'character_contact_list_corporate_labels' => $timestamp_columns, 'character_contact_list_corporates' => $timestamp_columns, 'character_contact_list_labels' => $timestamp_columns, 'character_contact_lists' => $timestamp_columns, 'character_contact_notifications' => $timestamp_columns, 'character_contract_items' => $timestamp_columns, 'character_contracts' => $timestamp_columns, 'character_industry_jobs' => $timestamp_columns, 'character_kill_mails' => $timestamp_columns, 'character_mail_message_bodies' => $timestamp_columns, 'character_mail_messages' => $timestamp_columns, 'character_mailing_list_infos' => $timestamp_columns, 'character_mailing_lists' => $timestamp_columns, 'character_market_orders' => $timestamp_columns, 'character_notifications' => $timestamp_columns, 'character_notifications_texts' => $timestamp_columns, 'character_planetary_colonies' => $timestamp_columns, 'character_planetary_links' => $timestamp_columns, 'character_planetary_pins' => $timestamp_columns, 'character_planetary_routes' => $timestamp_columns, 'character_researches' => $timestamp_columns, 'character_skill_in_trainings' => $timestamp_columns, 'character_skill_queues' => $timestamp_columns, 'character_standings' => $timestamp_columns, 'character_upcoming_calendar_events' => $timestamp_columns, 'character_wallet_journals' => $timestamp_columns, 'character_wallet_transactions' => $timestamp_columns, 'corporation_account_balances' => $timestamp_columns, 'corporation_asset_list_contents' => $timestamp_columns, 'corporation_asset_lists' => $timestamp_columns, 'corporation_bookmarks' => $timestamp_columns, 'corporation_contact_list_alliance_labels' => $timestamp_columns, 'corporation_contact_list_alliances' => $timestamp_columns, 'corporation_contact_list_labels' => $timestamp_columns, 'corporation_contact_lists' => $timestamp_columns, 'corporation_contract_items' => $timestamp_columns, 'corporation_contracts' => $timestamp_columns, 'corporation_customs_office_locations' => $timestamp_columns, 'corporation_customs_offices' => $timestamp_columns, 'corporation_industry_jobs' => $timestamp_columns, 'corporation_kill_mails' => $timestamp_columns, 'corporation_locations' => $timestamp_columns, 'corporation_market_orders' => $timestamp_columns, 'corporation_medals' => $timestamp_columns, 'corporation_member_medals' => $timestamp_columns, 'corporation_member_securities' => $timestamp_columns, 'corporation_member_security_logs' => $timestamp_columns, 'corporation_member_security_titles' => $timestamp_columns, 'corporation_member_trackings' => $timestamp_columns, 'corporation_shareholders' => $timestamp_columns, 'corporation_sheet_divisions' => $timestamp_columns, 'corporation_sheet_wallet_divisions' => $timestamp_columns, 'corporation_sheets' => $timestamp_columns, 'corporation_standings' => $timestamp_columns, 'corporation_starbase_details' => $timestamp_columns, 'corporation_starbases' => $timestamp_columns, 'corporation_titles' => $timestamp_columns, 'corporation_wallet_journals' => $timestamp_columns, 'corporation_wallet_transactions' => $timestamp_columns, 'eve_alliance_list_member_corporations' => $timestamp_columns, 'eve_alliance_lists' => $timestamp_columns, 'eve_api_call_lists' => $timestamp_columns, 'eve_api_keys' => $timestamp_columns, 'eve_character_info_employment_histories' => $timestamp_columns, 'eve_character_infos' => $timestamp_columns, 'eve_conquerable_station_lists' => $timestamp_columns, 'eve_error_lists' => $timestamp_columns, 'eve_ref_types' => $timestamp_columns, 'failed_jobs' => ['failed_at'], 'global_settings' => $timestamp_columns, 'job_trackings' => $timestamp_columns, 'kill_mail_attackers' => $timestamp_columns, 'kill_mail_details' => $timestamp_columns, 'kill_mail_items' => $timestamp_columns, 'map_jumps' => $timestamp_columns, 'map_kills' => $timestamp_columns, 'map_sovereignties' => $timestamp_columns, 'notifications' => $timestamp_columns, 'password_resets' => ['created_at'], 'people' => $timestamp_columns, 'person_members' => $timestamp_columns, 'schedules' => $timestamp_columns, 'security_logs' => $timestamp_columns, 'server_server_statuses' => $timestamp_columns, 'user_login_histories' => $timestamp_columns, 'user_settings' => $timestamp_columns, 'users' => $timestamp_columns]; // Loop over the tables and columns and alter the default value for // the columns. foreach ($timestamp_tables_and_columns as $table => $columns) { foreach ($columns as $column) { $sql = 'ALTER TABLE `' . $table . '` CHANGE `' . $column . '` `' . $column . '` TIMESTAMP NULL DEFAULT NULL;'; DB::update($sql); } } // Next, get the datetime columns fixed up $datetime_tables_and_columns = ['account_account_statuses' => ['paidUntil', 'createDate'], 'character_contracts' => ['dateIssued', 'dateExpired', 'dateAccepted', 'dateCompleted'], 'character_bookmarks' => ['created'], 'character_character_sheets' => ['DoB', 'cloneJumpDate', 'lastRespecDate', 'lastTimedRespec', 'remoteStationDate', 'jumpActivation', 'jumpFatigue', 'jumpLastUpdate'], 'character_chat_channel_members' => ['untilWhen'], 'character_contact_notifications' => ['sentDate'], 'character_contracts' => ['dateIssued', 'dateExpired', 'dateAccepted', 'dateCompleted'], 'character_industry_jobs' => ['startDate', 'endDate', 'pauseDate', 'completedDate'], 'character_mail_messages' => ['sentDate'], 'character_market_orders' => ['issued'], 'character_notifications' => ['sentDate'], 'character_planetary_colonies' => ['lastUpdate'], 'character_planetary_pins' => ['lastLaunchTime', 'installTime', 'expiryTime'], 'character_researches' => ['researchStartDate'], 'character_skill_in_trainings' => ['currentTQTime', 'trainingEndTime', 'trainingStartTime'], 'character_skill_queues' => ['startTime', 'endTime'], 'character_upcoming_calendar_events' => ['eventDate'], 'character_wallet_journals' => ['date'], 'character_wallet_transactions' => ['transactionDateTime'], 'corporation_bookmarks' => ['created'], 'corporation_contracts' => ['dateIssued', 'dateExpired', 'dateAccepted', 'dateCompleted'], 'corporation_industry_jobs' => ['startDate', 'endDate', 'pauseDate', 'completedDate'], 'corporation_market_orders' => ['issued'], 'corporation_medals' => ['created'], 'corporation_member_medals' => ['issued'], 'corporation_member_security_logs' => ['changeTime'], 'corporation_member_trackings' => ['startDateTime', 'logonDateTime', 'logoffDateTime'], 'corporation_starbase_details' => ['stateTimestamp', 'onlineTimestamp'], 'corporation_starbases' => ['stateTimestamp', 'onlineTimestamp'], 'corporation_wallet_journals' => ['date'], 'corporation_wallet_transactions' => ['transactionDateTime'], 'eve_alliance_list_member_corporations' => ['startDate'], 'eve_alliance_lists' => ['startDate'], 'eve_character_info_employment_histories' => ['startDate'], 'eve_character_infos' => ['corporationDate', 'nextTrainingEnds', 'allianceDate'], 'kill_mail_details' => ['killTime'], 'server_server_statuses' => ['currentTime']]; // Loop over the tables and columns and alter the default value for // the columns. foreach ($datetime_tables_and_columns as $table => $columns) { foreach ($columns as $column) { // Change the default value for the column $sql = 'ALTER TABLE `' . $table . '` CHANGE `' . $column . '` `' . $column . '` DATETIME NULL DEFAULT NULL;'; DB::update($sql); // Update values of 0000-00-00 00:00:00 to NULL $sql = 'UPDATE `' . $table . '` SET `' . $column . '` = NULL WHERE `' . $column . '` = \'0000-00-00 00:00:00\';'; DB::update($sql); } } }
public function test(Request $request) { DB::reconnect('mysql'); $ticket = Ticket::find(16); $this->dispatch(new TicketCreatedNotification($ticket)); }
/** * A little hack to reconnect to the database if we're in console mode and trying to find a deployment. * Should fix the error sending STMT_PREPARE problem that causes deployments to sit "pending" forever. * @return mixed */ public function findOrFail() { if (App::runningInConsole()) { DB::reconnect(); } return parent::__call('findOrFail', func_get_args()); }