Many websites including official site state about connecting database connections on a dbgroup, however I hardly found a website that talks about getting only an array of configuration.
This idea is that we can make several data adapter objects like OAuth\Pdo without an unused real database connection to get the config.
How can I achieve this?
Found an answer from looking at the system class CodeIgniter\Config\BaseConfig.
The files in app/Config including app/Config/Database.php are instances of BaseConfig, which means we can get the public properties of Database config by:
$database = new \Config\Database();
Getting configuration array by passing a dbgroup will then remain in three steps:
Duplicate a database connection in .env and update the values:
database.newdbgroup.hostname = localhost
database.newdbgroup.database = newdbgroup
database.newdbgroup.username = newdbgroup-username
database.newdbgroup.password = newdbgroup-password
database.newdbgroup.DBDriver = MySQLi
database.newdbgroup.DBPrefix =
Duplicate a database connection in app/Config/Database.php. We should not update the values this time:
public $newdbgroup = [
'DSN' => '',
'hostname' => 'localhost',
'username' => '',
'password' => '',
'database' => '',
'DBDriver' => 'MySQLi',
'DBPrefix' => '',
'pConnect' => false,
'DBDebug' => (ENVIRONMENT !== 'production'),
'charset' => 'utf8',
'DBCollat' => 'utf8_general_ci',
'swapPre' => '',
'encrypt' => false,
'compress' => false,
'strictOn' => false,
'failover' => [],
'port' => 3306,
];
Check the expected outcome:
$database = new \Config\Database();
echo '<pre>';
var_dump($database->newdbgroup);
echo '</pre>';
exit();
Which outputs:
array(17) {
["DSN"]=>
string(0) ""
["hostname"]=>
string(9) "localhost"
["username"]=>
string(19) "newdbgroup-username"
["password"]=>
string(19) "newdbgroup-password"
["database"]=>
string(10) "newdbgroup"
["DBDriver"]=>
string(6) "MySQLi"
["DBPrefix"]=>
string(0) ""
["pConnect"]=>
bool(false)
["DBDebug"]=>
bool(false)
["charset"]=>
string(4) "utf8"
["DBCollat"]=>
string(15) "utf8_general_ci"
["swapPre"]=>
string(0) ""
["encrypt"]=>
bool(false)
["compress"]=>
bool(false)
["strictOn"]=>
bool(false)
["failover"]=>
array(0) {
}
["port"]=>
int(3306)
}
Related
i am making an image storage function with laravel job queue via googledrive. i am trying to initialize and store my photo. It works with the code:
$filePut = file_get_contents($this->path);
Storage::cloud()->put($this->name, $filePut);
but i can't get the return id
i am changing to another method and here is my 2nd code:
public function handle(GoogleClient $googleDrive)
{
dd($googleDrive);
$driveService = new \Google_Service_Drive($googleDrive);
$fileMetadata = new \Google_Service_Drive_DriveFile([
'name' => $this->name,
]);
$file = $driveService->files->create($fileMetadata, [
'data' => file_get_contents($this->path),
'uploadType' => 'multipart',
'fields' => 'id',
]);
$driveService->getClient()->setUseBatch(true);
try {
$batch = $driveService->createBatch();
$userPermission = new \Google_Service_Drive_Permission([
'type' => 'anyone',
'role' => 'reader',
]);
$request = $driveService->permissions->create($file->id, $userPermission, ['fields' => 'id']);
$batch->add($request, 'user');
$results = $batch->execute();
} catch (\Exception $e) {
} finally {
$driveService->getClient()->setUseBatch(false);
}
I noticed the data received from dd($googleDrive) is no data :
App\Components\GoogleClient {#3225
#client: Google\Client {#3203
-auth: null
-http: null
-cache: null
-token: null
-config: array:29 [
"application_name" => ""
"base_path" => "https://www.googleapis.com"
"client_id" => ""
"client_secret" => ""
"credentials" => null
"scopes" => null
"quota_project" => null
"redirect_uri" => null
"state" => null
"developer_key" => ""
"use_application_default_credentials" => false
"signing_key" => null
"signing_algorithm" => null
"subject" => null
"hd" => ""
"prompt" => ""
"openid.realm" => ""
"include_granted_scopes" => null
"login_hint" => ""
"request_visible_actions" => ""
I try to store it before the queue then the $drivegoogle data I get is as follows:
Google\Client {#3146
-auth: null
-http: null
-cache: null
-token: array:6 [
"access_token" => "*************************************************************************************"
"expires_in" => "*************************************************************************************"
"scope" => "*************************************************************************************"
"token_type" => "*************************************************************************************"
"created" => "*************************************************************************************"
"refresh_token" => "*************************************************************************************"
]
-config: array:29 [
"application_name" => ""
"base_path" => "https://www.googleapis.com"
"client_id" => "*************************************************************************************"
"client_secret" => "*************************************************************************************"
"credentials" => null
"scopes" => null
"quota_project" => null
"redirect_uri" => null
"state" => null
"developer_key" => ""
"use_application_default_credentials" => false
"signing_key" => null
"signing_algorithm" => null
"subject" => null
"hd" => ""
"prompt" => ""
"openid.realm" => ""
"include_granted_scopes" => null
"login_hint" => ""
"request_visible_actions" =>
is there any workaround to get the id from the storage::put method, or is there another way to fix my current error, the error appears at new \Google_Service_Drive($googleDrive); constructor must be array or instance of Google\Client {"exception":"[object] (TypeError(code: 0): constructor must be array or instance of Google\\Client
$googleDrive = $googleDrive->getClient()
I am trying to create an issue with jira-ruby in the terminal. So far I have done the following (where username, password, site and project have been replaced with the proper values). I have been able to fetch issues, but not to create them. Jira-ruby return false when i try and save an issue
options = {
:username => "username",
:password => "password",
:site => 'site',
:context_path => '',
:auth_type => :basic
}
client = JIRA::Client.new(options)
issue = client.Issue.build
issue.save({
"fields" => {
"summary" => "blarg from in example.rb",
"project" => {"key" => "mykey"},
"issuetype" => {"id" => "1"}
}
})
=> false
issue.attrs
=> {"errorMessages"=>[], "errors"=>{"issuetype"=>"issue type is required"}, "summary"=>"blarg from in example.rb", "key"=>"somekey", "id"=>"someid", "self"=>"site", "exception"=>{"class"=>"Net::HTTPBadRequest", "code"=>"400", "message"=>"Bad Request"}}
What is the problem?
Thank you very much for reading this, its quite long!
I run my function:
public function createSpreadSheet()
{
$client = $this->getClient();
$service = new \Google_Service_Sheets($client);
// TODO: Assign values to desired properties of `requestBody`:
$requestBody = new \Google_Service_Sheets_Spreadsheet();
$response = $service->spreadsheets->create($requestBody);
echo '<pre>', var_export($response, true), '</pre>', "\n";
}
I got a result:
Google_Service_Sheets_Spreadsheet::__set_state(array(
'collection_key' => 'sheets',
'developerMetadataType' => 'Google_Service_Sheets_DeveloperMetadata',
'developerMetadataDataType' => 'array',
'namedRangesType' => 'Google_Service_Sheets_NamedRange',
'namedRangesDataType' => 'array',
'propertiesType' => 'Google_Service_Sheets_SpreadsheetProperties',
'propertiesDataType' => '',
'sheetsType' => 'Google_Service_Sheets_Sheet',
'sheetsDataType' => 'array',
'spreadsheetId' => '1QlBQo_YHQpiiMBWn6b6wSMVWkiFRx4grJhPParXUUSU',
'spreadsheetUrl' => 'https://docs.google.com/spreadsheets/d/1QlBQo_YHQpiiMBWn6b6wSMVWkiFRx4grJhPParXUUSU/edit',
'internal_gapi_mappings' =>
array (
),
modelData' =>
array (
),
'processed' =>
array (
),
'properties' =>
Google_Service_Sheets_SpreadsheetProperties::__set_state(array(
'autoRecalc' => 'ON_CHANGE',
'defaultFormatType' => 'Google_Service_Sheets_CellFormat',
'defaultFormatDataType' => '',
'iterativeCalculationSettingsType' => 'Google_Service_Sheets_IterativeCalculationSettings',
'iterativeCalculationSettingsDataType' => '',
'locale' => 'en_US',
'timeZone' => 'Etc/GMT',
'title' => 'Untitled spreadsheet',
'internal_gapi_mappings' =>
array (
),
'modelData' =>
array (
),
'processed' =>
array (
),
'defaultFormat' =>
Google_Service_Sheets_CellFormat::__set_state(array(
'backgroundColorType' => 'Google_Service_Sheets_Color',
'backgroundColorDataType' => '',
'bordersType' => 'Google_Service_Sheets_Borders',
'bordersDataType' => '',
'horizontalAlignment' => NULL,
'hyperlinkDisplayType' => NULL,
'numberFormatType' => 'Google_Service_Sheets_NumberFormat',
'numberFormatDataType' => '',
.........
.........
))
I access to the link it returned:
'https://docs.google.com/spreadsheets/d/1QlBQo_YHQpiiMBWn6b6wSMVWkiFRx4grJhPParXUUSU/edit'
it gives me this 'request access' page, then I press the request access
I open my email and get this:
Your message wasn't delivered to xxxxxx#xxxxxxxx.iam.gserviceaccount.com because the domain admanager-1x3x71x4x27x4.iam.gserviceaccount.com couldn't be found. Check for typos or unnecessary spaces and try again.
Is there something wrong and what should I do? I just want to open the file and check where it is.
Thank you very much!
I have a form search and i'd like to select data by boolean field. The problem is that if the select choice has false value (0) the query returns all data but if selected choice has true value (1) the query is correct.
In the formTye:
->add('publier', ChoiceType::class, array(
'required' => false,
'label' => 'Publier',
'choices' => array('oui' => '1', 'non' => '0'),
'multiple' => false,
'expanded' => false,
'attr' => array('class'=> 'form-control')
));
and in the query_builder
if (!empty($publier)) {
$qb->andWhere('a.publier = :publier')
->setParameter('publier', $publier );
}
if I remove this test : if (!empty($publier)) { and I select a false choice the returned data is correct but I can't remove this test.
I have changed
if (!empty($publier))
by
if (null !== $publier )
and it works fine now
I'm not sure I understand your question clearly, but if it's a boolean you want, you should try this:
->add('publier', ChoiceType::class, array(
'required' => false,
'label' => 'Publier',
'choices' => array(
'oui' => true,
'non' => false
),
'multiple' => false,
'expanded' => false,
'attr' => array('class'=> 'form-control')
));
Not sure if it will work. The way you have it with '1' and '0', those are strings (not integers).
I seem to be having a problem with 302 redirects using curb (Ruby's curl programs)
Here's the code snippet that is ** NOT working** (it's NOT doing the 302 redirect)
easy_options = {:follow_location => true, :enable_cookies => true, :useragent => 'curb', :cookiefile => 'cookie.txt'}
multi_options = {:pipeline => true}
url_fields = [
{
:url => 'https://x.y.z/webapps/login/',
:method => :post,
:follow_location => true,
:enable_cookies => true,
:useragent => 'curb',
:post_fields => {
'user_id' => 'xxxx',
'password' => 'xxxx',
'action' => 'login',
'encoded_pw' => Base64.strict_encode64('xxxx')},
}
]
Curl::Multi.http(url_fields,{:pipeline => true}) do |easy, code, method|
puts easy.header_str
end
Here's the code snippet that appears to be working (it's doing the 302 redirect)
easy_options = {:follow_location => true, :enable_cookies => true, :useragent => 'curb', :cookiefile => 'cookie.txt'}
multi_options = {:pipeline => true}
url_fields = [
{ :url => 'https://x.y.z/webapps/login/',
:post_fields => {
'user_id' => 'xxxx',
'password' => 'yyyy',
'action' => 'login',
'encoded_pw' => Base64.strict_encode64('yyyy')}}
]
Curl::Multi.post(url_fields, easy_options, multi_options) do|easy|
# do something interesting with the easy response
puts easy.last_effective_url
end
Question: Why is the first block not doing the 302 redirect as expected? :follow_location is set to true?
Thanks in advance!
Let me know if you need more information