/** * Execute the job. * * @return void */ public function handle() { // Query the CUCM to get numbers in the None partition $res = Utils::executeQuery('SELECT dnorpattern, description FROM numplan WHERE fkroutepartition IS NULL AND tkpatternusage = 2', $this->cluster); // Create a line in the CSV for the Cluster heading Storage::append($this->outFile, $this->cluster->name . ',' . $this->cluster->ip); //If we got results..... if ($res) { //Add the results to our CSV file foreach ($res as $dn) { Storage::append($this->outFile, implode(",", [$dn->dnorpattern, $dn->description])); } } }
/** * getConnections() function fetches all connections from * connection and table specified. Then returns a path * to a configuration file which gets imported and * deleted. * * @param $connection * @param $table * @return null|string */ public static function getConnections($connection, $table) { $connections = DB::connection($connection)->table($table)->get(); if (!empty($connections)) { /** * Create an empty array which will get populated with the data from * $connections in the correct format within the foreach statement * below file generation. */ $config = array(); /** * Generate a random string for the filename as it is temporary * and more secure. */ $random_string = ConnectionLoader::random_string(35); /** * Append the .php extension to the file name and store here * storage_path/app/$tempFile with some starting content. */ $tempFileName = $random_string . '.php'; $tempFile = Storage::disk('local')->put($tempFileName, '<?php return '); if ($tempFile === true) { /** * Loops through the connections checking the driver and pushes * correctly formatted array into the $config array. */ foreach ($connections as $connection) { $name = $connection->name; $driver = $connection->driver; if ($driver == 'sqlite') { $connection_config = array('driver' => $driver, 'database' => database_path($connection->database), 'prefix' => $connection->prefix); $config[$name] = $connection_config; } elseif ($driver == 'mysql') { $strict = $connection->strict; if ($strict == 1) { $strict = true; } else { $strict = false; } $password = $connection->password; if (empty($password)) { $connection_config = array('driver' => $driver, 'host' => $connection->host, 'database' => $connection->database, 'username' => $connection->username, 'password' => $password, 'charset' => $connection->charset, 'collation' => $connection->collation, 'prefix' => $connection->prefix, 'strict' => $strict); } else { $connection_config = array('driver' => $driver, 'host' => $connection->host, 'database' => $connection->database, 'username' => $connection->username, 'password' => Crypt::decrypt($password), 'charset' => $connection->charset, 'collation' => $connection->collation, 'prefix' => $connection->prefix, 'strict' => $strict); } $config[$name] = $connection_config; } elseif ($driver == 'pgsql') { $password = $connection->password; if (empty($password)) { $connection_config = array('driver' => $driver, 'host' => $connection->host, 'port' => $connection->port, 'database' => $connection->database, 'username' => $connection->username, 'password' => $password, 'charset' => $connection->charset, 'prefix' => $connection->prefix, 'schema' => $connection->schema); } else { $connection_config = array('driver' => $driver, 'host' => $connection->host, 'port' => $connection->port, 'database' => $connection->database, 'username' => $connection->username, 'password' => Crypt::decrypt($password), 'charset' => $connection->charset, 'prefix' => $connection->prefix, 'schema' => $connection->schema); } $config[$name] = $connection_config; } } /** * Append a var_export of $config to the temporary file and * append the semicolon. * * Returns the temporary filename. */ $endFile = ';'; Storage::append($tempFileName, var_export($config, true)); Storage::append($tempFileName, $endFile); return $tempFileName; } else { \error_log('Unable to create temporary file'); } } else { \error_log('Configuration File Connection Invalid.'); return null; } }