Solr Solaruim Client->ping is failing - solr

I am new to this stuff. I just inherited this olde system! I managed to get Solr running, and am trying to execute some old code that rebuilds the Solr data. The client ping is failing and I don't understand why.
Here is the code that is trying to initiate a re-index
// these are correct, now Solarium is falling over
// with a 404. pile of junk
print(SOLR_SERVER_HOSTNAME . "\n");
print(SOLR_SERVER_PORT . "\n");
print(SOLR_SERVER_CORE . "\n");
$options = array(
'adapteroptions' => array(
'host' => SOLR_SERVER_HOSTNAME,
'port' => SOLR_SERVER_PORT,
'core' => SOLR_SERVER_CORE,
'timeout' => 60
)
);
}
try {
// Ping the Solr server to check its availability
// create a new client. This seems to work
$this->client = new Solarium_Client($options);
if ($this->client) {
print("Solarium returned something \n");
print_r($this->client);
print("\n");
} else {
echo 'Solarium screwed the pooch';
}
// and create a ping whatever that means
// this also seems to work
$ping = $this->client->createPing();
if ($ping) {
print("ping creation worked \n");
print_r($ping);
} else {
print("ping creation failed \n");
}
// this always fails and terminate the
// program run
$this->client->ping($ping);
} catch (Solarium_Exception $e) {
print("exeption from ping request \n");
throw $e;
}
print("about to reset \n");
// Reset all filters and queries and process request params if requested
$this->reset($request);
}
The Solr admin screen is up. I have an empty collection1..
Here is the output from the trace I stuck in here
1/tmp/reindex.lock
15/01/18 17:38:54 [INFO] Index started
Index started
localhost
9999
collection1
Solarium returned something
Solarium_Client Object
(
[_options:protected] => Array
(
[adapter] => Solarium_Client_Adapter_Http
[adapteroptions] => Array
(
[host] => localhost
[port] => 9999
[core] => collection1
[path] => /solr/
[timeout] => 60
)
)
[_queryTypes:protected] => Array
(
[select] => Array
(
[query] => Solarium_Query_Select
[requestbuilder] => Solarium_Client_RequestBuilder_Select
[responseparser] => Solarium_Client_ResponseParser_Select
)
[update] => Array
(
[query] => Solarium_Query_Update
[requestbuilder] => Solarium_Client_RequestBuilder_Update
[responseparser] => Solarium_Client_ResponseParser_Update
)
[ping] => Array
(
[query] => Solarium_Query_Ping
[requestbuilder] => Solarium_Client_RequestBuilder_Ping
[responseparser] => Solarium_Client_ResponseParser_Ping
)
[mlt] => Array
(
[query] => Solarium_Query_MoreLikeThis
[requestbuilder] => Solarium_Client_RequestBuilder_MoreLikeThis
[responseparser] => Solarium_Client_ResponseParser_MoreLikeThis
)
[analysis-document] => Array
(
[query] => Solarium_Query_Analysis_Document
[requestbuilder] => Solarium_Client_RequestBuilder_Analysis_Document
[responseparser] => Solarium_Client_ResponseParser_Analysis_Document
)
[analysis-field] => Array
(
[query] => Solarium_Query_Analysis_Field
[requestbuilder] => Solarium_Client_RequestBuilder_Analysis_Field
[responseparser] => Solarium_Client_ResponseParser_Analysis_Field
)
[terms] => Array
(
[query] => Solarium_Query_Terms
[requestbuilder] => Solarium_Client_RequestBuilder_Terms
[responseparser] => Solarium_Client_ResponseParser_Terms
)
[suggester] => Array
(
[query] => Solarium_Query_Suggester
[requestbuilder] => Solarium_Client_RequestBuilder_Suggester
[responseparser] => Solarium_Client_ResponseParser_Suggester
)
)
[_pluginTypes:protected] => Array
(
[loadbalancer] => Solarium_Plugin_Loadbalancer
[postbigrequest] => Solarium_Plugin_PostBigRequest
[customizerequest] => Solarium_Plugin_CustomizeRequest
[parallelexecution] => Solarium_Plugin_ParallelExecution
[bufferedadd] => Solarium_Plugin_BufferedAdd
[prefetchiterator] => Solarium_Plugin_PrefetchIterator
)
[_pluginInstances:protected] => Array
(
)
[_adapter:protected] =>
[_requestBuilders:protected] =>
)
ping creation worked
Solarium_Query_Ping Object
(
[_options:protected] => Array
(
[resultclass] => Solarium_Result_Ping
[handler] => admin/ping
)
[_helper:protected] =>
[_params:protected] => Array
(
)
)
exeption from ping request
Failed to initialise Solr client:
Solr HTTP error: Not Found (404)
Failed to initialise Solr client: Solr HTTP error: Not Found (404)
Any hints? It's the first time I have seen this stuff.
Cheers,
Mark.

Fixed. The core name was getting flattened in another bit of code. Two constants for the same property. Two different values! – Addinall 22 secs

Related

I am trying to get all Power BI reports while this process I sent CURL request in PHP to authenticate the user but it's throwing below error response

Please help me how to resolve this issue.
Error Response:
Array
(
[error] => invalid_grant
[error_description] => AADSTS65001: The user or administrator has not consented to use the application with ID '27ccc3c6-6560-461c-bf42-c0f3f756fa7a' named 'DrCloudEHR - East'. Send an interactive authorization request for this user and resource.
Trace ID: c137e449-e653-43d8-88f8-9abb8499b100
Correlation ID: 0b2f5c0d-ac09-49bc-81f3-b8b95a185186
Timestamp: 2020-11-20 06:10:03Z
[error_codes] => Array
(
[0] => 65001
)
[timestamp] => 2020-11-20 06:10:03Z
[trace_id] => c137e449-e653-43d8-88f8-9abb8499b100
[correlation_id] => 0b2f5c0d-ac09-49bc-81f3-b8b95a185186
[suberror] => consent_required
)
CURL REQUEST code:
$curlPostToken = curl_init();
curl_setopt_array($curlPostToken, array(
CURLOPT_URL => "https://login.windows.net/common/oauth2/token",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => array(
grant_type => 'password',
scope => 'openid',
prompt => 'admin_consent',
client_secret => '~-8gGXjt~Ag7_o_N0~l9.K63Iza_FA49TR',
resource => 'https://analysis.windows.net/powerbi/api',
client_id => '27ccc3c6-6560-461c-bf42-c0f3f756fa7a', // Registered App ApplicationID
username => '*********g#*******.com', // for example john.doe#yourdomain.com
password => '**********' // Azure password for above user
)
));
$tokenResponse = curl_exec($curlPostToken);
$tokenError = curl_error($curlPostToken); print_r($tokenError);
curl_close($curlPostToken);
$tokenResult = json_decode($tokenResponse, true);
print_r($tokenResult); exit;

foreach inside foreach and out put first foreach in array

Assume I have an array called (data) and inside my array I have a foreach on products. I need to get each of these product packages inside this (data) array.
Here is what I've tried:
foreach ( $products as $product ) {
$data[] = [
'id' => $product->id,
'packages' => [],
]
foreach ( $product->packageId as $package ) {
$data[]['packages'] = [
'package_id' => $package['id'],
];
}
}
This returns:
- 0 [
id: 977
packages: []
]
- 1 [
packages
package_id: 14
]
- 2 [
packages
package_id: 15
]
I need to return something like this:
- 0 [
id: 977
packages: [
package_id: 14,
package_id: 15
]
]
Update
as #Helioarch and #albus_severus mentioned in they answers that I should create the package array first then include that into the data array
this solution will add the old array of packages in every time the products loops
For Example
product 1 has packages [1,2,3]
product 2 has packages [4,5,6]
in this my case here it will become
product 1 have packages [1,2,3]
product 2 will have packages [1,2,3,4,5,6] <- witch is wrong.
Update 2
Here is my full code
foreach ( $products as $product ) {
$sums = 0;
foreach ( $product->packageId as $package ) {
// Get the total existing inventory
$pckInvSum = $package->pckInventories
->where( 'expiry_date', '<', Carbon::today() )
->where( 'type', 'existing' )->sum( 'amount' );
// Get the total virtual inventory
$pckInvVirtual = $package->pckInventories->where( 'type', 'virtual' )->sum( 'amount' );
// create new array packages to add it to the main json
$packages[] = [
'package_id' => $package['id'],
'package_price' => $package['price'],
'unit_count' => $package['unit_count'],
'existing' => $pckInvSum,
'virtual' => $pckInvVirtual
];
$sums += $package->pckInventories->sum( 'amount' );
}
$data[] = [
'id' => $product->id,
'product_category_id' => $product->product_category_id,
'child_category_id' => $product->child_category_id,
'child_category_two_id' => $product->child_category_two_id,
'child_category_three_id' => $product->child_category_three_id,
'supplier_id' => $product->supplier_id,
'supplier_name' => $product->supplier->contact_name,
'option_category_id' => $product->option_category_id,
'tax_id' => $product->tax_id,
'barcode' => $product->barcode,
'low_price' => $product->low_price,
'image' => $product->image,
'cost' => $product->cost,
'name_ar' => $product->translations[0]->name,
'name_en' => $product->translations[1]->name,
'details_ar' => $product->translations[0]->details,
'details_en' => $product->translations[1]->details,
'sumInv' => $sums,
'campaign' => [
'id' => $product->campaign[0]->id,
'product_id' => $product->campaign[0]->product_id,
'price' => $product->campaign[0]->price,
'purchasesLimits' => $product->campaign[0]->purchasesLimits,
],
'packages' => $packages,
];
You should create the package array first then include that into the data array like so:
foreach ( $products as $product ) {
$packages = [];
foreach ( $product->packageId as $package ) {
$packages[] = [
'package_id' => $package['id'],
];
}
$data[] = [
'id' => $product->id,
'packages ' => $packages,
]
}
EDIT:
Please try again with a revised version of the code you provide below.
foreach ( $products as $product ) {
$sums = 0;
$packages = [];
foreach ( $product->packageId as $package ) {
// Get the total existing inventory
$pckInvSum = $package->pckInventories
->where( 'expiry_date', '<', Carbon::today() )
->where( 'type', 'existing' )->sum( 'amount' );
// Get the total virtual inventory
$pckInvVirtual = $package->pckInventories->where( 'type', 'virtual' )->sum( 'amount' );
// create new array packages to add it to the main json
$packages[] = [
'package_id' => $package['id'],
'package_price' => $package['price'],
'unit_count' => $package['unit_count'],
'existing' => $pckInvSum,
'virtual' => $pckInvVirtual
];
$sums += $package->pckInventories->sum( 'amount' );
}
$data[] = [
'id' => $product->id,
'product_category_id' => $product->product_category_id,
'child_category_id' => $product->child_category_id,
'child_category_two_id' => $product->child_category_two_id,
'child_category_three_id' => $product->child_category_three_id,
'supplier_id' => $product->supplier_id,
'supplier_name' => $product->supplier->contact_name,
'option_category_id' => $product->option_category_id,
'tax_id' => $product->tax_id,
'barcode' => $product->barcode,
'low_price' => $product->low_price,
'image' => $product->image,
'cost' => $product->cost,
'name_ar' => $product->translations[0]->name,
'name_en' => $product->translations[1]->name,
'details_ar' => $product->translations[0]->details,
'details_en' => $product->translations[1]->details,
'sumInv' => $sums,
'campaign' => [
'id' => $product->campaign[0]->id,
'product_id' => $product->campaign[0]->product_id,
'price' => $product->campaign[0]->price,
'purchasesLimits' => $product->campaign[0]->purchasesLimits,
],
'packages' => $packages,
];
}

Converting HttpFoundation\Response to an array

My symfony request is returning array with entity object and setstate method.
This is the dump of the array.
array (
0 =>
HealthyLiving\ApiBundle\Entity\User::__set_state(array(
'id' => 1,
'username' => 'admin',
'password' => '123',
'email' => 'batoosay#gmail.com',
'isActive' => false,
)),
)
And here is the code:
public function loginAction()
{
$restresult = $this->getDoctrine()->getRepository('ApiBundle:User')->findAll();
if ($restresult === null) {
return new View("there are no users exist", Response::HTTP_NOT_FOUND);
}
echo '<pre>' . var_export($restresult, true) . '</pre>';die;
return new JsonResponse(
$restresult
);
}
The JsonResponse is empty because of the strange array. How do i convert this array of object to json ?
try to serialize with JMS like this:
$serializer = $this->get('jms_serializer');
return new Response(
$serializer->serialize($restresult, 'json')
);

Smarty check if items in array more than 1

I use smarty to display different code and I want to check if the array of some phrase contains more than 1 items.
I want to create a if phrase, that checks if the array contains only 1 value or more. Something like this, but of course that correct.
{if $domains|#array < 1}
How can I achieve that?
The code looks like this:
$domains
Smarty_Variable Object (3)
->value = Array (3)
0 => Array (17)
domain => "example1.com"
regperiod => "1"
dnsmanagement => "on"
emailforwarding => ""
idprotection => ""
addonsCount => 1
eppvalue => ""
fields => Array (0)
configtoshow => true
hosting => false
1 => Array (17)
domain => "example2.com"
regperiod => "1"
dnsmanagement => "on"
emailforwarding => ""
idprotection => ""
addonsCount => 1
eppvalue => ""
fields => Array (0)
configtoshow => true
hosting => false
2 => Array (17)
domain => "example3.com"
regperiod => "1"
dnsmanagement => "on"
emailforwarding => ""
idprotection => ""
addonsCount => 1
eppvalue => ""
fields => Array (0)
configtoshow => true
hosting => false
->nocache = false
You can use count (from the php function http://php.net/manual/es/function.count.php):
{if $domains|#count < 1}

Status Update using Nerilcrookes' OAuth extension to CakePHP HttpSocket returns "incorrect signature error"

I'm using Neilcrookes' OAuth extension to CakePHP HttpSocket ( http://www.neilcrookes.com/2010/04/12/cakephp-oauth-extension-to-httpsocket/ )
My request looks like:
Array (
[method] => POST
[uri] => Array (
[host] => api.twitter.com
[path] => 1/statuses/update.json
)
[auth] => Array (
[method] => OAuth
[oauth_token] => xxx
[oauth_token_secret] => xxx
[oauth_consumer_key] => xxx
[oauth_consumer_secret] => xxx
)
[body] => Array (
[status] => Hello World
)
)
I have the oauth_token and oauth_token_secret from the previous request from the user
response looks like {“request”:”\/1\/statuses\/update.json”,”error”:”Incorrect signature”}
Thanks in Advance
Just a wild guess: But could it be that your signature isn't correct?

Resources