Method 'getCfg' is deprecated joomla - joomla4

My phpstorm reports that the following is deprecated:
$app = Factory::getApplication();
$sitename = $app->getCfg('sitename');
What is the new correct way to go for this in Joomla 4 ?

We can fix this using 2 methods,
Method 1:
use Joomla\CMS\Factory;
$app = Factory::getApplication();
$sitename = $app->getCfg('sitename');
Method 2:
$app = JFactory::getApplication();
$sitename = $app->getCfg('sitename');

Related

Upload Offline Conversion migration to V9

I used to upload offline conversion using following code in v201809 version as provided at
https://github.com/googleads/googleads-php-lib/blob/master/examples/AdWords/v201809/Remarketing/UploadOfflineConversions.php
$oAuth2Credential = (new OAuth2TokenBuilder())->fromFile()->build();
$session = (new AdWordsSessionBuilder())->fromFile()->withOAuth2Credential($oAuth2Credential)->withClientCustomerId($customerid)->enablePartialFailure()->build();
$adWordsServices = new AdWordsServices();
$offlineConversionService = $adWordsServices->get($session, OfflineConversionFeedService::class);
$conversionName="OfflineConv";
$feed = new OfflineConversionFeed();
$feed->setConversionName($conversionName);
$feed->setConversionTime($conversionTime);
$feed->setConversionValue($conversionValue);
$feed->setGoogleClickId($gclid);
$offlineConversionOperation = new OfflineConversionFeedOperation();
$offlineConversionOperation->setOperator(Operator::ADD);
$offlineConversionOperation->setOperand($feed);
$offlineConversionOperations = [$offlineConversionOperation];
$result = $offlineConversionService->mutate($offlineConversionOperations);
Now I am upgrading to V9, I have used the code as provided at
https://github.com/googleads/google-ads-php/blob/main/examples/Remarketing/UploadOfflineConversion.php
$oAuth2Credential = (new OAuth2TokenBuilder())->fromFile()->build();
$googleAdsClient = (new GoogleAdsClientBuilder())->fromFile()->withOAuth2Credential($oAuth2Credential)->build();
//$conversionName="OfflineConv";
$conversionName = ConversionActionType::WEBPAGE;
$clickConversion = new ClickConversion([
'conversion_action' => ResourceNames::forConversionAction($customerId, $conversionName),
'gclid' => $gclid,
'conversion_value' => $conversionValue,
'conversion_date_time' => $conversionTime,
'currency_code' => 'USD'
]);
$conversionUploadServiceClient = $googleAdsClient->getConversionUploadServiceClient();
$result = $conversionUploadServiceClient->uploadClickConversions($customerid, [$clickConversion], true);
The problem is when we set $conversionName="OfflineConv"; we get following error.
Resource name 'customers/9025381111/conversionActions/OfflineConv' is malformed: expected 'customers/{customer_id}/conversionActions/{ConversionType.conversion_type_id}'., at conversions[0].conversion_action
and when we set $conversionName = ConversionActionType::WEBPAGE; we get following error.
This customer does not have an import conversion action that matches the conversion action provided., at conversions[0].conversion_action
Can someone help me?
Conversion Name must match the conversion action that you've already set up in your account. You're passing the enum value for the type.
It should be something like $conversionName = "OfflineConversions"
where "OfflineConversions" is exactly the name of the conversion in the conversions section of the web UI.
ConversionName has been removed from V9, use $conversionActionId as in example on github.
You need to try use parameter ctId from url your "OfflineConversions" in Google Ads UI as $conversionActionId.
Or try the solution from here.
For your example, replace this
$conversionName = ConversionActionType::WEBPAGE;
on this
$conversionName = {ctId from url};
You need to first create a click conversion
click_conversion = adwords_client.get_type("ClickConversion")
conversion_action_service = adwords_client.get_service('ConversionActionService')
click_conversion.conversion_action = (
conversion_action_service.conversion_action_path(
customer_id, conversion_action_id
)
)
The conversion_action_id is equivalent to conversion_name of previous version.
You can find the id using following snippet
ads: GoogleAdsServiceClient = self.adwords_client.get_service('GoogleAdsService')
pages = ads.search(query="SELECT conversion_action.id, conversion_action.name FROM conversion_action where conversion_action.name={conversion_name}", customer_id={customer_id})
for page in pages:
print(page.conversion_action)
Then you upload the conversion
click_conversion.gclid = gclid
click_conversion.conversion_value = conversion_value
click_conversion.conversion_date_time = conversion_time
click_conversion.currency_code = currency_code
conversion_upload_service = self.adwords_client.get_service("ConversionUploadService")
request = self.adwords_client.get_type("UploadClickConversionsRequest")
request.customer_id = customer_id
request.conversions.append(click_conversion)
request.partial_failure = True
conversion_upload_response = (
conversion_upload_service.upload_click_conversions(
request=request,
)
)
uploaded_click_conversion = conversion_upload_response.results[0]
print(
f"Uploaded conversion that occurred at "
f'"{uploaded_click_conversion.conversion_date_time}" from '
f'Google Click ID "{uploaded_click_conversion.gclid}" '
f'to "{uploaded_click_conversion.conversion_action}"'
)

ngx.escape_uri() didn't work on '/'?

I'm trying to encode a url as an arg value like this
url = "http://test.com?a=1&b=2"
encode_url = "http://domain?url="..ngx.escape_uri(url)
then it became
http://domain?url=http%3A//test.com%3Fa%3D1%26b%3D2
but i want to this
http://domain?url=http%3a%2f%2ftest.com%3fa%3d1%26b%3d2
and I also try ngx.encode_args(), it's the same
Does anyone know why? And how should I do?
host = "http://test.com"
uri = "?a=1&b=2"
encode_host = ngx.encode_args({[host]=true})
encode_args = ngx.escape_uri(uri)
encode_url = "http://domain?url=" .. encode_host .. encode_args

Zend framework 2 return the view contents as string

In zf1, I could just do this:
$jsonData['html'] = $this->view
->render('search/partials/search-results-list.phtml');
$this->view->jsonData = $jsonData;
$this->getHelper('viewRenderer')->setRender('index-json');
$this->getHelper('layout')->disableLayout();
I tried the code below in zf2 but returns nothing on the $jsonData['html'].
$viewVar = array('some variables to be passed here');
$partial = $this->getServiceLocator()->get('viewhelpermanager')->get('partial');
$html = 'search/partials/search-results-list.phtml';
$jsonData['html'] = $partial($html, $viewVar);
return new JsonModel($jsonData);
What would be the equivalent of this in zf2?
Thanks in advance
You could pass your view to the PHP View Renderer's render method:
https://github.com/zendframework/zf2/blob/master/library/Zend/View/Renderer/PhpRenderer.php#L446

How to refer to one configuration variable from other configuration variable inside Config.groovy

For example:
Config.groovy:
// ...
grails.variable1 = "a"
grails.varibale2 = "${grails.variable1}bc"
//...
UPDATE 1
Way shown above works with grails 2.2.3. For older versions of grails please use solution #tim_yates suggested
You need to declare a variable:
def rootVar = 'a'
grails.variable1 = rootVar
grails.varibale2 = "${rootVar}bc"
Or you might be able to do it via a closure (not tested):
grails.variable1 = 'a'
grails.varibale2 = { -> "${grails.variable1}bc" }()

call stored procedure in vb script

I have created a stored procedure. I tested it in the query analyser like this EXEC test '10/12/2012'. It is OK. But I called it following way in the vb script. It not OK.
InstanceVar = CreateObject("ADODB.Recordset")
InstanceVar.ActiveConnection = ConnVar
InstanceVar.Source = "EXEC Test '" & Date() & "'"
InstanceVar.CursorType = 3
InstanceVar.CursorLocation = 3
InstanceVar.Open()
I have got 80040E14 error. How can I solve it
I realise this is a bit late, but I found this question when looking for a solution to the same problem. I've solved it like this:
Set cmd = Server.CreateObject("ADODB.Command")
cmd.ActiveConnection = ConnVar
cmd.CommandType = adCmdStoredProc
cmd.CommandText = "Test"
cmd.Parameters.Append(cmd.CreateParameter("#my_date", adVarChar, adParamInput,10))
cmd.Parameters("#my_date") = "10/12/2012"
Set rsResults = Server.CreateObject("ADODB.Recordset")
rsResults.CursorLocation = adUseClient
rsResults.Open cmd,,adOpenForwardOnly,adLockBatchOptimistic
Using CursorLocation = adUseClient means you can navigate the rsResults RecordSet using MoveNext, MoveFirst etc.

Resources