Mismatched entity and/or field definitions following database update - drupal-8

I have a Drupal site that I'm trying to update to the latest version 8.6.8. The problem is when I run the command 'drush updatedb', I see this error in the console;
Failed: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '1-0-0-en' for key 'PRIMARY': INSERT INTO {taxonomy_term__parent} (bundle, entity_id, revision_id, langcode, [error]
delta, parent_target_id) VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2, :db_insert_placeholder_3, :db_insert_placeholder_4,
:db_insert_placeholder_5), (:db_insert_placeholder_6, :db_insert_placeholder_7, :db_insert_placeholder_8, :db_insert_placeholder_9, :db_insert_placeholder_10, :db_insert_placeholder_11),
(:db_insert_placeholder_12, :db_insert_placeholder_13, :db_insert_placeholder_14, :db_insert_placeholder_15, :db_insert_placeholder_16, :db_insert_placeholder_17),
(:db_insert_placeholder_18, :db_insert_placeholder_19, :db_insert_placeholder_20, :db_insert_placeholder_21, :db_insert_placeholder_22, :db_insert_placeholder_23),
(:db_insert_placeholder_24, :db_insert_placeholder_25, :db_insert_placeholder_26, :db_insert_placeholder_27, :db_insert_placeholder_28, :db_insert_placeholder_29),
(:db_insert_placeholder_30, :db_insert_placeholder_31, :db_insert_placeholder_32, :db_insert_placeholder_33, :db_insert_placeholder_34, :db_insert_placeholder_35),
(:db_insert_placeholder_36, :db_insert_placeholder_37, :db_insert_placeholder_38, :db_insert_placeholder_39, :db_insert_placeholder_40, :db_insert_placeholder_41),
(:db_insert_placeholder_42, :db_insert_placeholder_43, :db_insert_placeholder_44, :db_insert_placeholder_45, :db_insert_placeholder_46, :db_insert_placeholder_47),
(:db_insert_placeholder_48, :db_insert_placeholder_49, :db_insert_placeholder_50, :db_insert_placeholder_51, :db_insert_placeholder_52, :db_insert_placeholder_53),
(:db_insert_placeholder_54, :db_insert_placeholder_55, :db_insert_placeholder_56, :db_insert_placeholder_57, :db_insert_placeholder_58, :db_insert_placeholder_59),
(:db_insert_placeholder_60, :db_insert_placeholder_61, :db_insert_placeholder_62, :db_insert_placeholder_63, :db_insert_placeholder_64, :db_insert_placeholder_65),
(:db_insert_placeholder_66, :db_insert_placeholder_67, :db_insert_placeholder_68, :db_insert_placeholder_69, :db_insert_placeholder_70, :db_insert_placeholder_71),
(:db_insert_placeholder_72, :db_insert_placeholder_73, :db_insert_placeholder_74, :db_insert_placeholder_75, :db_insert_placeholder_76, :db_insert_placeholder_77),
(:db_insert_placeholder_78, :db_insert_placeholder_79, :db_insert_placeholder_80, :db_insert_placeholder_81, :db_insert_placeholder_82, :db_insert_placeholder_83),
(:db_insert_placeholder_84, :db_insert_placeholder_85, :db_insert_placeholder_86, :db_insert_placeholder_87, :db_insert_placeholder_88, :db_insert_placeholder_89),
(:db_insert_placeholder_90, :db_insert_placeholder_91, :db_insert_placeholder_92, :db_insert_placeholder_93, :db_insert_placeholder_94, :db_insert_placeholder_95),
(:db_insert_placeholder_96, :db_insert_placeholder_97, :db_insert_placeholder_98, :db_insert_placeholder_99, :db_insert_placeholder_100, :db_insert_placeholder_101)
As a result of this, when I look at the Status Report in Drupal, it shows that there are still database updates outstanding;
Mismatched entity and/or field definitions
The following changes were detected in the entity type and field definitions.
Taxonomy term
The Taxonomy term entity type needs to be updated.
The Published field needs to be installed.
The issue is, I have no idea why this is happening as it's a site I have only recently taken control of from another developer.

Truncating the table 'taxonomy_term__parent' fixed this.

In order to apply Pending Schema Updates.
Try "drush updb" and then
Try running "drush entity-updates".

Related

Dataflow batch template provided by google does not work

I want to run the sample in [1].
However, when I do this, I get the following error:
org.apache.beam.sdk.Pipeline$PipelineExecutionException: org.apache.avro.UnresolvedUnionException: Not in union ["null",{"type":"int","logicalType":"date"}]: 1990-01-01 (field=birthday)
at org.apache.beam.runners.direct.DirectRunner$DirectPipelineResult.waitUntilFinish (DirectRunner.java:353)
at org.apache.beam.runners.direct.DirectRunner$DirectPipelineResult.waitUntilFinish (DirectRunner.java:321)
at org.apache.beam.runners.direct.DirectRunner.run (DirectRunner.java:216)
at org.apache.beam.runners.direct.DirectRunner.run (DirectRunner.java:67)
at org.apache.beam.sdk.Pipeline.run (Pipeline.java:317)
at org.apache.beam.sdk.Pipeline.run (Pipeline.java:303)
at org.apache.beam.examples.Test.run (Test.java:299)
at org.apache.beam.examples.Test.main (Test.java:232)
at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke (Method.java:566)
at org.codehaus.mojo.exec.ExecJavaMojo$1.run (ExecJavaMojo.java:282)
at java.lang.Thread.run (Thread.java:834)
Caused by: org.apache.avro.UnresolvedUnionException: Not in union ["null",{"type":"int","logicalType":"date"}]: 1990-01-01 (field=birthday)
at org.apache.avro.generic.GenericDatumWriter.writeField (GenericDatumWriter.java:223)
at org.apache.avro.generic.GenericDatumWriter.writeRecord (GenericDatumWriter.java:210)
at org.apache.avro.generic.GenericDatumWriter.writeWithoutConversion (GenericDatumWriter.java:131)
at org.apache.avro.generic.GenericDatumWriter.write (GenericDatumWriter.java:83)
at org.apache.avro.generic.GenericDatumWriter.write (GenericDatumWriter.java:73)
at org.apache.beam.sdk.coders.AvroCoder.encode (AvroCoder.java:317)
at org.apache.beam.sdk.coders.Coder.encode (Coder.java:136)
at org.apache.beam.sdk.util.CoderUtils.encodeToSafeStream (CoderUtils.java:82)
at org.apache.beam.sdk.util.CoderUtils.encodeToByteArray (CoderUtils.java:66)
at org.apache.beam.sdk.util.CoderUtils.encodeToByteArray (CoderUtils.java:51)
at org.apache.beam.sdk.util.CoderUtils.clone (CoderUtils.java:141)
at org.apache.beam.sdk.util.MutationDetectors$CodedValueMutationDetector.<init> (MutationDetectors.java:115)
at org.apache.beam.sdk.util.MutationDetectors.forValueWithCoder (MutationDetectors.java:46)
at org.apache.beam.runners.direct.ImmutabilityCheckingBundleFactory$ImmutabilityEnforcingBundle.add (ImmutabilityCheckingBundleFactory.java:112)
at org.apache.beam.runners.direct.ParDoEvaluator$BundleOutputManager.output (ParDoEvaluator.java:301)
at org.apache.beam.repackaged.direct_java.runners.core.SimpleDoFnRunner.outputWindowedValue (SimpleDoFnRunner.java:267)
at org.apache.beam.repackaged.direct_java.runners.core.SimpleDoFnRunner.access$900 (SimpleDoFnRunner.java:79)
at org.apache.beam.repackaged.direct_java.runners.core.SimpleDoFnRunner$DoFnProcessContext.output (SimpleDoFnRunner.java:413)
at org.apache.beam.repackaged.direct_java.runners.core.SimpleDoFnRunner$DoFnProcessContext.output (SimpleDoFnRunner.java:401)
at org.apache.beam.sdk.io.gcp.bigquery.BigQueryIO$TypedRead$3.processElement (BigQueryIO.java:1139)
For reference, the version of avro is 1.10.1
Is there any solution?
[1]https://github.com/GoogleCloudPlatform/DataflowTemplates/blob/master/v2/bigquery-to-parquet/src/main/java/com/google/cloud/teleport/v2/templates/BigQueryToParquet.java
This looks like a bug.
The Avro schema is retrieved from BigQuery and it indicates that the field birthday should be a nullable integer that represents a date.
The actual data when written is a string or date (cannot tell from the output).
I browsed Avro's code and it seems that exception is only thrown when writing data, not reading. So it appears this happening during the write to Parquet, perhaps because the GenericRecord loaded from the Avro files has converted the birthday field so it is no longer an integer.
You may be able to work around this by avoiding the DATE type.

How to get item attributes via api?

We are using cloud Dynamics 365 Business Central and trying to get items with all attributes via OData.
In Microsoft documentation we found this endpoint:
api.businesscentral.dynamics.com/v1.0[our tenant id]/Sandbox/ODataV4/Company('CRONUS%20DE')/items
But unfortunately, the response does not contain item attributes and values, such as Farbe, Tiefe, etc.
Next, we tried to add new Web Services. But some of this endpoints return empty values and some of them (7506, 7507, 7508, 7510) don't work and return:
No HTTP resource was found that matches the request URI
Objects 7500, 7501, 7503 contain information about attributes. But non of them (7500 - 7510) does not contain a relation between Item, Attributes, and Values.
Maybe there is another way to get items with their attribute values? We also tried to research microsoft graph but not successful.
i am having similar troubles with this. i find the dynamics api to be exceptionally unintuitive and difficult to use. the furthest i have been able to get has been to go into the api settings for dynamics and uncover the tables for a few item attributes (i believe that the table numbers are as those below:
7500 - Item Attribute
7501 - Item Attribute Value
7502 - Item Attribute Translation
7504 - Item Attribute Value Selection
7505 - Item Attribute Value Mapping
i cannot comment on why 7503 is missing.
using 7500 as an example, when you uncover the table, the system provides a resulting endpoint (unfortunately, they always promote OData, and the outdated SOAP resource; i can't figure out why they have such a vendetta against the simple and easy-to-use REST endpoint).
https://api.businesscentral.dynamics.com/v2.0/<TENANT_ID>/<ENVIRONMENT_NAME>/ODataV4/Company('COMPANY_IDENTIFIER')/ItemAttributes
using this endpoint, you can get a listing of the attribute types themselves (e.g. let's say you've defined an attribute called 'BaseColor', you should get a result here for the name of the attribute 'BaseColor', its ID, its type, etc.),
with the ItemAttributeValues endpoint, you should get the actual attribute values that are in existence (e.g. for some item, you happened to set its 'BaseColor' attribute to 'Blue', you should get a response for this attribute value with a attribute type of 'BaseColor', a value, as 'Blue' along with the entity's ID, etc).
yet, when it comes to any instantiated attribute values for items, i can't figure out how to get the association of the attributes with those items. i expect that the "item attribute value mapping" option would be something along the lines of a item_id - attribute_id pair so that for any item in question, one could query the attributes list with something like a filter. but as you said, upon uncovering some of these elements, their respective endpoints return nothing. you get to the point where you say 'OH...AWSOME! there is a value-item mapping. that makes sense, and i can definitely use that'. a few moments later, the API spits in your face with an error, or craps on you by returning something you don't expect like an empty data set.
this api is a constant uphill battle, and totally riddled with landmines. a complete blow-me-up-pain-in-the-arse.
EDIT: 2021-06-09
i've looked into this some more. i was able to set up an export package for the various tables in question, specifically 7500, 7501, and 7505. the magical table was 7505 as it is the relationship between an attribute value and the item with which it is associated. exporting the package to excel results in good data. yet, when trying to expose this information in the OData resource, something strange happens:
in web services, i try to open up page 7505 which populates the object name as ItemAttributeValueMapping and i set the service name to 'ItemAttributeValueMapping'. This is normal.
the system complains when i fail to specify that the object type is a page. so, i go back in the line and set the selection to "Page"
when i tab through to publish the change, the object name automatically changes to 'ItemAttributeValueTranslations'.
EDIT: 2021-06-15
After a lot of fiddling about, i finally reached a point where i decided that the only way to address this was to write an al query which would expose the appropriate value-item mapping information. there is a page which provides some source code for doing this:
github AL-Code-Samples
to get something out of the API, i had to use microsoft visual studio code. there are a few good videos on how to get this up and running to get a test app working for your business central instance (i used eric hougaar's videos: Getting started with Business Central AL Development).
when you have set up your app to connect to your instance by inserting your tenant and entering your credentials, you can modify the source code as below to create a query in your system.
query 50102 "<YOUR_QUERY_NAME>"
{
QueryType = API;
APIPublisher = '<YOUR_NAME>';
APIGroup = '<YOUR_APP_GROUP>';
APIVersion = 'v1.0';
Caption = '<YOUR CAPTION>';
EntityName = '<YOUR_QUERY_NAME>';
EntitySetName = '<YOUR_API_ENDPOINT_NAME>';
elements
{
dataitem(Item; Item)
{
column(No_; "No.")
{
}
column(Description; Description)
{
}
column(Unit_Cost; "Unit Cost")
{
}
dataitem(Item_Attribute_Value_Mapping; "Item Attribute Value Mapping")
{
DataItemLink = "No." = Item."No.";
column(Item_Attribute_ID; "Item Attribute ID")
{
}
column(Item_Attribute_Value_ID; "Item Attribute Value ID")
{
}
dataitem(QueryElement6; "Item Attribute")
{
DataItemLink = ID = Item_Attribute_Value_Mapping."Item Attribute ID";
column(Name; Name)
{
}
dataItem(Queryelement10; "Item Attribute Value")
{
DataItemLink = "Attribute ID" = Item_Attribute_Value_Mapping."Item Attribute ID",
ID = Item_Attribute_Value_Mapping."Item Attribute Value ID";
column(Value; Value)
{
}
column(Numeric_Value; "Numeric Value")
{
}
}
}
}
}
}
}
once this code gets successfully uploaded to your server and returning a page (you have to wait for it), you can then use specified query number to expose the data in the API by going to business central's "web services" and adding a 'Query' to item 50102 (or whatever number you use). the endpoint will automatically be populated and you can use it to send you back the necessary JSON which will show a product, with its attribute values.
hope that helps.
You should try with below endpoint:
/v2.0/tenant_id/enviornment_name/ODataV4/Company(company_id)/Items

Doctrine2 loading DoctrineExtensions

I want to use the DAY() and YEAR() functions in my Doctrine2 query builder. But somehow I keep on getting errors:
Fatal error: Uncaught Doctrine\ORM\Query\QueryException: SELECT DAY(h.date) AS day FROM Entities\Hit h GROUP BY day in
PHP Code:
$totalHits = $this->registry->entityManager->getRepository('Entities\Hit')
->createQueryBuilder('h')
->select('DAY(h.date) AS day')
->groupBy('day')
->getQuery()->getResult();`
Loading the doctrineExtensions through composer or through the autoloader wouldn't fix it:
$classLoader = new \Doctrine\Common\ClassLoader('DoctrineExtensions', __DIR__.'/../vendor/beberlei/DoctrineExtensions');
$classLoader->register();
Am I loading the DoctrineExtensions just wrongly or is there something else?
Fixed. Adding:
$entityManagerConfig->addCustomDatetimeFunction('YEAR', 'DoctrineExtensions\Query\Sqlite\Year');
$entityManagerConfig->addCustomDatetimeFunction('MONTH', 'DoctrineExtensions\Query\Sqlite\Month');
$entityManagerConfig->addCustomDatetimeFunction('DAY', 'DoctrineExtensions\Query\Sqlite\Day');
solved the problem

create an order on Prestashop API : error with module name

I'm trying to create an order through the Prestashop API (v1.6.1.13). I havn't written any module, my goal is just to use its API without installing anything on the prestashop.
Creating an order requires a module name. If I leave it blank I get the error:
Validation error: "Property Order->module is empty"
If I write a fake name it says :
Validation error: "Property Order->module is not valid"
What should I do ? While I have the same issue with the payment field ?
Here is what I'm sending :
<prestashop>
<order>
<id_address_delivery>1299</id_address_delivery>
<id_address_invoice>1300</id_address_invoice>
<id_cart>218</id_cart>
<id_currency>1</id_currency>
<id_lang>2</id_lang>
<id_customer>214</id_customer>
<id_carrier>2</id_carrier>
<current_state>2</current_state>
<module></module>
<invoice_number>0</invoice_number>
<delivery_number>0</delivery_number>
<valid>1</valid>
<date_add>2017-06-27 23:00:46</date_add>
<date_upd>2017-06-28 11:50:13</date_upd>
<id_shop_group>1</id_shop_group>
<id_shop>1</id_shop
<payment>MyPayment</payment>
<recyclable>0</recyclable>
<gift>0</gift>
<mobile_theme>0</mobile_theme>
<total_discounts>0</total_discounts>
<total_discounts_tax_incl>0</total_discounts_tax_incl>
<total_discounts_tax_excl>0</total_discounts_tax_excl>
<total_paid>27</total_paid>
<total_paid_tax_incl>27</total_paid_tax_incl>
<total_paid_tax_excl>27</total_paid_tax_excl>
<total_paid_real>27</total_paid_real>
<total_products>27</total_products>
<total_products_wt>27</total_products_wt>
<total_shipping>0</total_shipping>
<total_shipping_tax_incl>0</total_shipping_tax_incl>
<total_shipping_tax_excl>0</total_shipping_tax_excl>
<carrier_tax_rate>0</carrier_tax_rate>
<total_wrapping>0</total_wrapping>
<total_wrapping_tax_incl>0</total_wrapping_tax_incl>
<total_wrapping_tax_excl>0</total_wrapping_tax_excl>
<conversion_rate>1</conversion_rate>
<reference>170627369</reference>
<associations>
<order_rows>
<order_row>
<product_id>2</product_id>
<product_attribute_id>7</product_attribute_id>
<product_quantity>2</product_quantity>
<product_name>Blouse</product_name>
<product_reference>demo_2</product_reference>
<product_ean13>0</product_ean13>
<product_price>27</product_price>
<unit_price_tax_incl>27</unit_price_tax_incl>
<unit_price_tax_excl>27</unit_price_tax_excl>
</order_row>
</order_rows>
</associations>
</order>
</prestashop>
Any help/idea would be greatly appreciate, thanks !
After some debug steps in the payment module I found the solution.
The module should be a valid module name (I use "bankwire") and payment can be wathever you want (the name of the external source for example).
I was testing an address which country was disabled... Enabling the country fix the issue.
What a pity Prestashop doesn't respond the reason on the API call... Even if activating the DEV mode of prestashop and DEBUG of the PaymentModule.
Thanks for your help sarcom !
You need Enable the payment options(like payment by check) in prestashop admin side and then need to add the module with prefix ps_moduleName without any space.
I did like this,
$xml->order->module= "ps_".strtolower(str_replace(' ', '', $order_data['payment_method']));
You can try this if there is any error or If you have any better solution then it me know.
Thanks.

composite and foreign keys as primary key doctrine 2 + zend framework 2

I have been wondering why my mappings and the controller actions are not working. For this I need to refer to my previous post, where I have described my entities and database schema, which can be found here. I need to start a new post since there were no further updates and I thought this the only way to get attention of the Doctrine + Zend Pros.
As described in my previous post, I have a Zend Form, the user can enter teamId and teamName, further he has the choice to select multiple players from the drop down list on the form and can allocate players to the team. So basically that is my goal to achieve with Doctrine and Zend. For that I wrote my entities described in the previous post and right now I want to add the code from my controller to persist the entities.
Controller:
public function addAction()
{
$form = new TeamForm($this->getEntityManager());
$form->get('submit')->setAttribute('value', 'Add');
$request = $this->getRequest();
if ($request->isPost())
{
$team = new Team();
$player = new Player();
$teamPlayers = new TeamPlayer();
$form->setInputFilter($typeset->getInputFilter());
$form->setData($request->getPost());
if ($form->isValid())
{
$team->populate($form->getData());
$teamPlayers->setPlayer($player);
$teamPlayers->setTeam($team);
$this->getEntityManager()->persist($teamPlayers);
$this->getEntityManager()->flush();
//Reroute to the index page once the data is successfully added
}
}
//return form array
return array(
'form' => $form
);
}
So that is basically what Im doing in my controller to save the entities into two tables (team Table and teamPlayer Table), as already the player Table is populated with data. So I want to add players to the team and assign that values in these two tables.
Right now I can see my form and when I enter the data and press submit nothing is happening, i can see the form with no action. When the data is successfully saved into the database then I reroute it to the index page which is not happening.
Any help would be appreciated, to point out the error Im making either in mapping section or in the controller side.
The official documentation especially from Doctrine 2 is too global and is particulary not that clear for my requirement.
let's try to solve it by updating this answer by steps :
step 1 :
your words implied to me that , you might have some issues in from validation , so lets check if you are passing this $form->isValid()
if ($form->isValid())
{
$team->populate($form->getData());
$teamPlayers->setPlayer($player);
$teamPlayers->setTeam($team);
$this->getEntityManager()->persist($teamPlayers);
$this->getEntityManager()->flush();
//Reroute to the index page once the data is successfully added
}else{
var_dump($form->getMessages());
}
I can also suggest you to use doctrine commandline : doctrine orm:validate-schema , this command will help you to check if your entity mapping is ok plus your database mapping is also okay , i see it as handy to to debug your doctrine2 entity 
ps : I havn't read your entities in depth yet