gRPC: Failed to parse binary descriptor - php

I've been following this tutorial: https://tsh.io/blog/grpc-php/
I have everything imported, however Im getting failed to parse binary descriptor in this file.
` $pool = \Google\Protobuf\Internal\DescriptorPool::getGeneratedPool();
if (static::$is_initialized == true) {
return;
}
\GPBMetadata\Google\Protobuf\GPBEmpty::initOnce();
$pool->internalAddGeneratedFile(
'
�
bookstore.protoendpoints.examples.bookstore""
Shelf
id (
theme ( "1
Book
id (
author (
title ( "K
ListShelvesResponse4
shelves (2#.endpoints.examples.bookstore.Shelf"H
CreateShelfRequest2
shelf (2#.endpoints.examples.bookstore.Shelf"
GetShelfRequest
shelf ("#
DeleteShelfRequest
shelf ("!
ListBooksRequest
shelf ("F
ListBooksResponse1
books (2".endpoints.examples.bookstore.Book"T
CreateBookRequest
shelf (0
book (2".endpoints.examples.bookstore.Book"-
GetBookRequest
shelf (
book ("0
DeleteBookRequest
shelf (
book (2�
BookstoreZ
ListShelves.google.protobuf.Empty1.endpoints.examples.bookstore.ListShelvesResponse"f
CreateShelf0.endpoints.examples.bookstore.CreateShelfRequest#.endpoints.examples.bookstore.Shelf"`
GetShelf-.endpoints.examples.bookstore.GetShelfRequest#.endpoints.examples.bookstore.Shelf"Y
DeleteShelf0.endpoints.examples.bookstore.DeleteShelfRequest.google.protobuf.Empty"n
ListBooks..endpoints.examples.bookstore.ListBooksRequest/.endpoints.examples.bookstore.ListBooksResponse"c
CreateBook/.endpoints.examples.bookstore.CreateBookRequest".endpoints.examples.bookstore.Book"]
GetBook,.endpoints.examples.bookstore.GetBookRequest".endpoints.examples.bookstore.Book"W
DeleteBook/.endpoints.examples.bookstore.DeleteBookRequest.google.protobuf.Empty"B;
\'com.google.endpoints.examples.bookstoreBBookstoreProtoPbproto3',
true
);`
Googles suggestions have not helped. Im using this implemented into a laravel project with php8.1.
The code inside the internalAddGeneratedFile function was already there upon implementing the package.
Tried following the guide, followed many possible solutions on the interwebs to no avail.
Just trying to run a basic call to return all books.

Related

How can I customize the filter of the product grid on the admin side in order to filter by RANGE?

Hope you are all good and in great shape.
TLDR: How can I filter my product grid on the admin side using a WEIGHT RANGE?
I am a newbie in Magento and I have been doing some progress over the last months on the basics of customizing Magento to our small company. I had a request from the sales team which I am struggling to get to term. We sell a kind of product which has a different weight to every item and the final price of the product is calculated by multiplying a variable rate by the weight. It makes the weight a very important attribute in the system not only for the sales/logistics, but also for the client's decision making. Therefore, I need to filter the product catalog grid on the admin side by weight, but not by a specific number, instead, I need a RANGE of weight. (From ...kg to ...kg) I managed to create the field, but I am struggling on the part were the action happens. Please take a look on the screenshots below:
Weight range in filters
Weight in columns
This is the structure of the module that I created:
module structure
And here is the code on the file AddWeightFieldToCollection.php which I am struggling with:
<?php
namespace Diamwill\WeightFilter\Ui\DataProvider\Product;
use Magento\Framework\Data\Collection;
use Magento\Ui\DataProvider\AddFieldToCollectionInterface;
class AddWeightFieldToCollection implements AddFieldToCollectionInterface
{
public function addField(Collection $collection, $field, $alias = null)
{
$mg_eav_attribute = $collection->getResource()->getTable('mg_eav_attribute');
$mg_catalog_product_entity_decimal = $collection->getResource()->getTable('mg_catalog_product_entity_decimal');
$collection->getSelect()->joinLeft(
['soa' => $mg_eav_attribute],
'soa.entity_type_id = 4 AND soa.attribute_code = \'weight\'',
null
);
$collection->getSelect()->joinLeft(
['dcrt' => $mg_catalog_product_entity_decimal],
'soa.attribute_id = dcrt.attribute_id',
['code']
);
$collection->joinField(
'weight_range',
'mg_catalog_product_entity',
'value',
'mg_catalog_product_entity.entity_id = soa.entity_id AND soa.store_id = 0',
null,
'left'
);
}
}
Basically, I know that I have to join the product tables to get weight, which in SQL terms would be something like this:
SELECT
w1.value AS 'weight'
FROM
mg_catalog_product_entity AS prod
LEFT JOIN
mg_catalog_product_entity_decimal w1 ON
prod.entity_id = w1.entity_id
AND w1.store_id = 0
AND w1.attribute_id = (SELECT
attribute_id
FROM
mg_eav_attribute
WHERE
attribute_code = 'weight'
AND entity_type_id = (SELECT
entity_type_id
FROM
mg_eav_entity_type
WHERE
entity_type_code = 'catalog_product'));
Which I am not capable of linking with the Collection class and apply to the column, in order to filter. Can someone help me with the code? I am happy to read a tutorial to learn or to get a certain book/article with more information on the topic.
Please, I do not want to buy a plugin/module in order to do that. I would like to learn how to do it.
Thanks to anyone who can help me.
Have a great day!

Joining two SugarCRM modules on linked field using SugarQuery()

Background and Context
I am attempting to create a custom REST module in SugarCRM 8.0 that joins two modules on a linked field. The two modules are;
Accounts ( a OOTB module )
ConsumerLeads ( a custom module )
These two modules are a linked field named w002_consumerleads_accounts_1 such that when I invoke the following endpoint I get a JSON response with all the ConsumerLead data associated with that specific account uuid.
/rest/v11_4/Accounts/{ account_uuid }/link/w002_consumerleads_accounts_1
However, instead of returning the joined results based on the account uuid, my custom module returns the the joined results based on a different account attribute that uniquely identifies an account.
/rest/v11_4/customer/{ customer_id }/leads
The reason I am attempting to build a custom module for this ( instead of using the predefined rest api listed above ) is due to the fact that the system invoking this call does not know the sugar account uuid, and instead knows a business key that uniquely identifies the account ( and is an attribute on the Accounts module ).
The Issue
When I use SugarQuery in my custom rest module to join Accounts and ConsumerLeads my results do not match the results specified in the first rest api ( the predefined rest api ). The result only returns the Accounts module, and does not join the ConsumerLeads module.
The issue is with the joining of the two modules on the linked field; the issue is not related to using the customer uuid v. the account uuid.
Reference Implementations
Based on the SugarCRM Developers Guide I written the following piece of code.
public function GetLinkLeads($api, $args) {
try {
$query = new SugarQuery();
$query->from(BeanFactory::getBean('Accounts'));
$query->join('w002_consumerleads_accounts_1');
$query->limit(10);
$results = $query->execute();
return $results;
} catch ( Exception $e ) {
return $e->getCode();
}
return 1;
}
Based on all the information I can gather, this function should return the first 10 account records joined with their ConsumerLeads. However, the response only contains the Accounts module data, it does not join the ConsumerLeads data.
Additionally, I have also tried the following way.
public function GetLinkLeads($api, $args) {
try {
$account = BeanFactory::getBean('Accounts', '4606e963-9213-7764-d83f-4cc050c8473d');
if ( $account->load_relationship('w002_consumerleads_accounts_1') ) {
$lead = $account->w002_consumerleads_accounts_1->getBeans();
return $lead;
}
} catch ( Exception $e ) {
return $e->getCode();
}
return 1;
}
Where 4606e963-9213-7764-d83f-4cc050c8473d is an account uuid that has associated ConsumerLeads, but I still cannot get ConsumerLeads data to return.
Question
I would like to either:
Use SugarQuery() to join these two modules based on a linked field
Use the default rest api to join the two modules based on an attribute on the Accounts module (not the account uuid)
I have found this exact question on Stack Overflow and the implementation above is based off the recommendation from that post. However, it still is not joining the records.
What you want to achieve should work OOTB using the filter API and specifying the required field's contents in your requests filter definition. Then you should receive the linked record you wanted.
It should work similar to https://stackoverflow.com/a/50608304/4068476
As quick test you could try calling this in your browser or program (here: GET, that's why I pass filter in query string)
/rest/v11_4/w002_ConsumerLeads?filter[0][w002_consumerleads_accounts_1.consumer_id]={ customer_id }
Notes:
I guessed the spelling of the module name in the URL, make sure to get uppercase/lowercase right.
If you want to receive both the Accounts and the ConsumerLeads in a single request - just use the /bulk API to wrap two requests into one.
Try the following code:
function outright_load_relationship( $left_bean, $rel_name,$return_beans = 0 ) {
$rel_obj = $left_bean->load_relationship( $rel_name );
if ( !$rel_obj ){
$rel_name =outright_get_bean_fields( $rel_name );
$rel_obj = $left_bean->load_relationship( $rel_name );
}
if( $return_beans ){
$relatedBeans = $left_bean->$rel_name->getBeans();
return $relatedBeans;
}
return $left_bean->$rel_name;
}
function outright_get_bean_fields( $left_bean, $fld_name = false, $fld_key = false ) {
if( !$fld_name && !$fld_key ) {
return $left_bean->field_defs;
} else {
foreach( $left_bean->field_defs as $key=>$value ) {
if( $fld_name && $key == $fld_name ) {
return $left_bean->field_defs[$key];
} else if( $fld_key && $value[$fld_key] == $fld_name ){
return $left_bean->field_defs[$key];
}
}
}
}
All you need to pass correct $rel_name in above functions. Please let me know if this does not work.

How do I find mininimum value of multiple XML nodes & create an output in WP-ALL-IMPORT?

I am having trouble trying to get the lowest value of multiple xml nodes from an external XML feed. The feed is this XML feed: http://genusvs.co.uk/xml2015.xml
As you can see, all the xml values node are all called something different. there are 8832 cars in the feed. This is an example of one.
<vehicle>
<capid>32076</capid>
<vehicleref>1100128291</vehicleref>
<type>Car</type>
<manufacturer>VAUXHALL</manufacturer>
<model>ZAFIRA ESTATE</model>
<shortmodtext>ZAFIRA</shortmodtext>
<derivative>1.8i Design 5dr</derivative>
<additionalfreetext/>
<paint>Metallic</paint>
<created>22/05/2015 00:20:00</created>
<updated>22/05/2015 00:20:00</updated>
<notes/>
<discount>GENUS TERMS</discount>
<dealercontribution>GENUS TERMS</dealercontribution>
<deliverycharge/>
<registeredstatus/>
<registrationdate/>
<mustbeorderedby/>
<mustbedeliveredby/>
<commission>300</commission>
<source>ARVAL</source>
<vrb/>
<approxleadtime/>
<doors>5</doors>
<transmission>1</transmission>
<fueltype>1</fueltype>
<listprice/>
<Price2Year10kMaintainedCH>568.0600</Price2Year10kMaintainedCH>
<Price2Year10kNotMaintainedCH>548.8600</Price2Year10kNotMaintainedCH>
<Price2Year20kMaintainedCH>605.5000</Price2Year20kMaintainedCH>
<Price2Year20kNotMaintainedCH>569.9900</Price2Year20kNotMaintainedCH>
<Price2Year30kMaintainedCH>647.4800</Price2Year30kMaintainedCH>
<Price2Year30kNotMaintainedCH>591.5900</Price2Year30kNotMaintainedCH>
<Price3Year10kMaintainedCH>452.9400</Price3Year10kMaintainedCH>
<Price3Year10kNotMaintainedCH>427.4500</Price3Year10kNotMaintainedCH>
<Price3Year20kMaintainedCH>489.2800</Price3Year20kMaintainedCH>
<Price3Year20kNotMaintainedCH>447.2000</Price3Year20kNotMaintainedCH>
<Price3Year30kMaintainedCH>528.0100</Price3Year30kMaintainedCH>
<Price3Year30kNotMaintainedCH>465.8100</Price3Year30kNotMaintainedCH>
<Price4Year10kMaintainedCH>391.8600</Price4Year10kMaintainedCH>
<Price4Year10kNotMaintainedCH>361.2900</Price4Year10kNotMaintainedCH>
<Price4Year20kMaintainedCH>424.9000</Price4Year20kMaintainedCH>
<Price4Year20kNotMaintainedCH>378.7100</Price4Year20kNotMaintainedCH>
<Price4Year30kMaintainedCH>488.3100</Price4Year30kMaintainedCH>
<Price4Year30kNotMaintainedCH>403.4700</Price4Year30kNotMaintainedCH>
<Price2Year10kMaintainedPCH>694.7160</Price2Year10kMaintainedPCH>
<Price2Year10kNotMaintainedPCH>671.6760</Price2Year10kNotMaintainedPCH>
<Price2Year20kMaintainedPCH>739.6440</Price2Year20kMaintainedPCH>
<Price2Year20kNotMaintainedPCH>697.0320</Price2Year20kNotMaintainedPCH>
<Price2Year30kMaintainedPCH>790.0200</Price2Year30kMaintainedPCH>
<Price2Year30kNotMaintainedPCH>722.9520</Price2Year30kNotMaintainedPCH>
<Price3Year10kMaintainedPCH>557.0040</Price3Year10kMaintainedPCH>
<Price3Year10kNotMaintainedPCH>526.4160</Price3Year10kNotMaintainedPCH>
<Price3Year20kMaintainedPCH>600.6120</Price3Year20kMaintainedPCH>
<Price3Year20kNotMaintainedPCH>550.1160</Price3Year20kNotMaintainedPCH>
<Price3Year30kMaintainedPCH>647.0880</Price3Year30kMaintainedPCH>
<Price3Year30kNotMaintainedPCH>572.4480</Price3Year30kNotMaintainedPCH>
<Price4Year10kMaintainedPCH>483.9240</Price4Year10kMaintainedPCH>
<Price4Year10kNotMaintainedPCH>447.2400</Price4Year10kNotMaintainedPCH>
<Price4Year20kMaintainedPCH>523.5720</Price4Year20kMaintainedPCH>
<Price4Year20kNotMaintainedPCH>468.1440</Price4Year20kNotMaintainedPCH>
<Price4Year30kMaintainedPCH>599.6640</Price4Year30kMaintainedPCH>
<Price4Year30kNotMaintainedPCH>497.8560</Price4Year30kNotMaintainedPCH>
<ncaprating>0</ncaprating>
<co2>168</co2>
<bhp/>
<mpgcombined>39.2</mpgcombined>
<zerotosixtytwo/>
<topspeed/>
<cc/>
</vehicle>
i need to the import to read all the prices, and also create a minimum price (no inclusive of 0 or null) from all the 2, 3, 4 year - 10k, 20k, 30k - maintained and non-maintained, business or personal and import this as a custom value..
i have already managed to change them to 2 decimal places... creating a separate function for each and having a function code for each xml property in the functions.php part of WP All Import
eg .
<?php
// 10k - maintained - personal
function p2y10kmp($p2y10kmp){ $p2y10kmp = number_format($p2y10kmp, 2, '.', ''); return $p2y10kmp;}
function p3y10kmp($p3y10kmp){ $p3y10kmp = number_format($p3y10kmp, 2, '.', ''); return $p3y10kmp;}
function p4y10kmp($p4y10kmp){ $p4y10kmp = number_format($p4y10kmp, 2, '.', ''); return $p4y10kmp;}
?>
I have done this as will need all the separate values for different places on the website... the minimum value i am struggling to work out how to get, will just be as a 'from £ +VAT'
Also all of the function values
function p4y10knmp($p4y10knmp){
$p4y10kmp = number_format($p4y10kmp, 2, '.', '');
return $p4y10kmp;
}
are imported like
[([p4y10knmch({Price4Year10kNotMaintainedCH[1]})] as required by WP ALL IMPORT
I have also tried creating an array from the added function values but i could not get anything to work with the min(array)?
example: `
$displayfrom = min(array_diff(array_map('intval', $values), array(0))); return $displayfrom;`
If anyone can help i will happily help by giving access if needed.
The website is currently running on www.cocoonoffers.uk if you wanted to get a jist of what i am trying to do, at the moment the site is running from a local version of the xml feed, with just 21 cars in the feed. when finished, will be using the full 8832 cars
(The price value in the custom field is just a static value at the moment [p4y10knmch({Price4Year10kNotMaintainedCH[1]})]

add user stories as children to feature

I was able to add features as children to initiatives by updating the parent field of the feature to point to the initiative (add features to initiative as children (php api))
I assumed this would be the same way to do add user stories as children to features -- by updating the field of the user story to point to its feature.
This is the code that's giving me errors:
$rally->update("story", $story['ObjectID'], array('Parent' => $feature['ObjectID']));
This is the error I'm getting:
PHP Fatal error: Uncaught exception 'RallyApiError' with message 'Could not read: Could not read referenced object 13317970914'
It seems like it's not letting me reference the feature ID..why is this happening?
You may update PortfolioItem field on a story.
In WS API doc Parent field on a Hierarchical Requirement(a.k.a. story) is expected to be another Hierarchical Requirement. It cannot be a Feature.
Also, Feature field on a story is read-only, and UserStories collection on Feature is read-only. That leaves us with the option to update PortfolioItem field on a story.
Here is a Ruby code that illustrates it:
#rally = RallyAPI::RallyRestJson.new(config)
obj = {}
obj["Name"] = "new story efd"
new_s = #rally.create("hierarchicalrequirement", obj)
query = RallyAPI::RallyQuery.new()
query.type = "portfolioitem"
query.fetch = "Name,FormattedID"
query.workspace = {"_ref" => "https://rally1.rallydev.com/slm/webservice/v2.0/workspace/11111" }
query.project = {"_ref" => "https://rally1.rallydev.com/slm/webservice/v2.0/project/2222" }
query.query_string = "(FormattedID = \"F22\")"
result = #rally.find(query)
feature = result.first
field_updates={"PortfolioItem" => feature}
new_s.update(field_updates)

Hide Drupal nodes from search

I made a private section on a drupal site by writing a module that checks the RERQUEST_URI for the section as well as user role. The issue I am running into now is how to prevent those nodes/views from appearing in the search.
The content types used in the private section are used in other places in the site.
What's the best way to get Druapl search to ignore the content/not index/not display it in search results?
There is a wonderful article that explains just this on the lullabot site.
It's worth reading the comments to the post too, because people there suggested alternate ways of doing that, also by mean of contrib modules (rather than implementing some hooks in your own code). Code for D6 is in the comment as well.
HTH!
The lullabot article is a bit outdated and contains many blunt approaches. It also contains the answer in the comments - the Search Restrict module which works for DP6 and allows fine-grained and role-based control. Everything else either prevents content from being indexed, which may not be desirable if there are different access levels to content, or affects all search queries equally, which will also not work if there are different access levels.
If the content types used within the Private section are also used elsewhere how are you hoping to filter them out of the search results (note that I've not looked at the lullabot article by mac yet).
Basically, if you look at the details of two nodes, one private and one public, what differentiates them?
Note: I'm assuming that you want the nodes to appear to users with access to the Private area but not to 'anonymous' users.
For Drupal 7.
You can hide the node from search results by using custom field. In my case, I have created a custom field in the name of Archive to the desired content type and with the help of that custom field you can write the my_module_query_alter functionality.
Code
function my_module_query_alter(QueryAlterableInterface $query) {
$is_search = $is_node_search = FALSE;
$node_alias = FALSE;
foreach ( $query->getTables() as $table ) {
if ( $table['table'] == 'search_index' || $table['table'] == 'tracker_user') {
$is_search = TRUE;
}
if ( $table['table'] == 'node' || $table['table'] == 'tracker_user') {
$node_alias = $table['alias'];
$is_node_search = TRUE;
}
}
if ( $is_search && $is_node_search ) {
$nids = [];
// Run entity field query to get nodes that are 'suppressed from public'.
$efq = new EntityFieldQuery();
$efq->entityCondition('entity_type', 'node')
->fieldCondition('field_archive', 'value', 1, '=');
$result = $efq->execute();
if ( isset($result['node']) ) {
$nids = array_keys($result['node']);
}
if ( count($nids) > 0 ) {
$query->condition(sprintf('%s.nid', $node_alias), $nids, 'NOT IN');
}
}
}

Categories