Migrating drupal 6 to drupal 7 - drupal

Basically we wanted to move a portion of our drupal 6 site to our drupal 7 build. Using the migrate module. While migrating 155 nodes with their comments and taxonomy(2 vocabs, one is fixed the other is comma seperated) the last 30 fail giving me this error:
291 Error PDOException: SQLSTATE[HY000]: General error: 1366 Incorrect integer value: '' for column 'tid' at row 1: INSERT INTO {taxonomy_index} (nid, tid, sticky, created) VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2, :db_insert_placeholder_3); Array ( [:db_insert_placeholder_0] => 3057 [:db_insert_placeholder_1] => [:db_insert_placeholder_2] => 0 [:db_insert_placeholder_3] => 1282050381 ) in taxonomy_field_insert() (line 1675 of /u01/facebase/drupal-7.0/modules/taxonomy/taxonomy.module).
291 Error SQLSTATE[HY000]: General error: 1366 Incorrect integer value: '' for column 'tid' at row 1
I'm migrating my terms using this query:
$query = db_select("$this->_db.term_data", 'td')
->fields('td', array('tid', 'name', 'weight'))
->condition('v.vid', 7);
$query->innerJoin("$this->_db.vocabulary", 'v', 'td.vid=v.vid');
I do this for 2 vocabularies, and then I map just the name, format, and weight. Then i'm using this query while migrating the nodes:
$query = db_select("$this->_db.node", 'n')
->fields('n', array('nid', 'vid', 'type', 'title', 'uid', 'status', 'created', 'changed', 'comment'))
->fields('tn', array('tid'))
->fields('nr', array('title', 'body', 'teaser'))
->condition('n.type', 'dev_content');
$query->leftJoin("$this->_db.term_node", 'tn', 'tn.vid =n.vid');
$query->leftJoin("$this->_db.node_revisions", 'nr', 'nr.vid = n.vid');
$query->addExpression('GROUP_CONCAT(DISTINCT tn.tid)', 'term_list');
$query->groupBy('n.nid');
Then i'm mapping the term_list for each vocabulary like this:
$this->addFieldMapping('field_dev_tags', 'term_list')
->separator(',')
->sourceMigration('DevCenterTerm')
->arguments(array('source_type' => 'tid'));
$this->addFieldMapping('field_dev_category', 'term_list')
->separator(',')
->sourceMigration('DevCenterTermPrep')
->arguments(array('source_type' => 'tid'));
I know this is happening due to the terms, as when i don't map the term_list all the nodes get created, but thats about it. Any ideas?

Is this an issue with those nodes not having a taxonomy assigned to them? If this is the case, try adding a default value to the taxonomy field mapping.
$this->addFieldMapping('field_dev_category', 'term_list')
->separator(',')
->sourceMigration('DevCenterTermPrep')
->arguments(array('source_type' => 'tid'))->defaultValue(12);
In the beer.inc example, this is documented in the comments:
You can also use both together - if a default value is provided in
addition to a source field, the default value will be applied to any
rows where the source field is empty or NULL.

Related

Symfony 5 Search on a DateTimeColumn datatables

I am using Omines Symfony DataTable Bundle https://omines.github.io/datatables-bundle/#doctrine-orm to organize my event table.
I am unable to search on my "Début" and "Fin" columns which are of type Datetime Column. I'm guessing because since these are DateTime objects I'm guessing it can't find a match.
mytable
If I type "08/19/2020" it doesn't find any results for me.
Here: https://datatables.net/forums/discussion/44218/how-do-i-search-on-a-datetime-column it advises to format the date on the server side, so I tried that (of course j 've installed the doctrine extensions to be able to use date_format):
->createAdapter(ORMAdapter::class, [
'entity' => Event::class,
'query' => function (QueryBuilder $builder) use ($eventStatus) {
$builder
->select('e')
->addSelect('DATE_FORMAT(e.startDate, "%d/%m/%Y")')
->addSelect('ca')
->addSelect('ci')
->addSelect('u')
->from(Event::class, 'e')
->join('e.category', 'ca')
->join('e.city', 'ci')
->join('e.user', 'u')
->andWhere('e.status = :status')
->setParameter('status', $eventStatus)
->orderBy('e.id', 'DESC')
;
},
])
I also changed my dateStart column to TextColumn:
->add('startDate', TextColumn::class, ['label' => 'Début', 'field' => 'e.startDate', 'render' => function($value, $context) {
return sprintf(
'%s<br>
%s',
$value,
$context->getStartAt()->format('H\hi'),
);
}])
And I have this error:
Uncaught PHP Exception Doctrine \ ORM \ Query \ QueryException: "[Syntax Error] line 0, col 34: Error: Expected StateFieldPathExpression | string | InputParameter | FunctionsReturningStrings | AggregateExpression, got '"' "
I do not see where the problem is.
Thanks for your help.
It's difficult to tell from the question you are asking, but there are certain things that look problematic in your code.
First, you use a custom query, but you don't use any WHERE clause with the date.
Second, your formatting of the column is not named. The result can't be accessed since it doesn't have a name. You can name it with the keyword AS:
->addSelect('DATE_FORMAT(e.startDate, "%d/%m/%Y") AS startDateFormatted')
Third, you use joins and then you shouldn't use ORMAdapter but FetchJoinORMAdapter (this will help you solve problems with pagination when using joins).
In my opinion, you shouldn't try to format the startDate in the query, but check the documentation and use a Criteria
https://omines.github.io/datatables-bundle/#doctrine-orm

MariaDB error with query

I'm getting following error when executing query .
Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ''0', '25'' at line 1
here is the query
$sqlData = 'SELECT * FROM users WHERE u_id_id = :UID_ID ORDER BY :ORDER_BY :ORDER_TYPE limit :START, :DATA_LENGTH';
$params = array(
":UID" => $uId,
":ORDER_BY" => $orderBy,
":ORDER_TYPE" => $orderType,
":START" => $start,
":DATA_LENGTH" => $length
);
$queryData = \registry::getDBHandler()->prepare($sqlData);
$queryData->execute($params);
var_dump($queryData->execute($params));
note
here is the var dum output of paramas
array (size=5)
':UID' => string '66' (length=2)
':ORDER_BY' => string 'id' (length=2)
':ORDER_TYPE' => string 'asc' (length=3)
':START' => string '0' (length=1)
':DATA_LENGTH' => string '25' (length=2)
Prepared statements let you bind variables to the WHERE (and I think SELECT) clauses of an SQL query. Unfortunately, they do not let you bind to the ORDER BY or LIMIT (or FROM) clauses. For that, you will need to manually append to the string.
Since those values are not being entered by the user, you should be safe from SQL injection if you just do:
$sqlData = "SELECT * FROM users WHERE u_id_id = :UID_ID ORDER BY $orderBy $orderType LIMIT $start, $length";
(Note the double quotes around the string)
And then your $params array would just be:
$params = array(":UID" => $uId);
If you are worried about SQL injection, then you can use the following to help with that:
For your ORDER BY, you can make sure that your $orderBy is in a hard-coded list of fields and reject it if it is not.
For $orderType, just simply ensure it is equal to either "asc" or "desc" (possibly ignoring case).
With $start and $length, make sure they are integers. You can also try to use intval() to convert them if need be.
If you follow these rules, then it should be safe to append these variables into your SQL query. Since $uId is part of the WHERE, you can use the prepared variable for it and that is fine.

PDOException : SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '308' for key 'PRIMARY': INSERT INTO {node}

I have a big issue today on my website using Drupal 7.22.
This issue appear on new node creation from an admin.
PDOException : SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '308' for key 'PRIMARY': INSERT INTO {node} (nid, vid, type, language, title, uid, status, created, changed, comment, promote, sticky, tnid, translate) 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); Array ( [:db_insert_placeholder_0] => 308 [:db_insert_placeholder_1] => 308 [:db_insert_placeholder_2] => evenements [:db_insert_placeholder_3] => fr [:db_insert_placeholder_4] => TEST [:db_insert_placeholder_5] => 1 [:db_insert_placeholder_6] => 0 [:db_insert_placeholder_7] => 1381931095 [:db_insert_placeholder_8] => 1381931095 [:db_insert_placeholder_9] => 1 [:db_insert_placeholder_10] => 0 [:db_insert_placeholder_11] => 0 [:db_insert_placeholder_12] => 0 [:db_insert_placeholder_13] => 0 ) dans drupal_write_record() (ligne 7136 dans /var/www/carioca/includes/common.inc).
I have checked the database and the last node id is 294.
Does anyone have an idea how to solve this issue ?
Thanks for your help.
If you have a PhpMyAdmin for your Database, have a look at the tables: node & node_revision. Could be that you have different indexes in there and causes that the id cannot be inserted.
Your issue is not that there is already an entry in the DB but that node & node_revision (or other table) has different state as the other tables does. The data within your DB seems to not be consistent.
Are you having custom table handles within your modules? Fix the Id issues and use the node_load or user_load Drupal API functions instead of custom DB calls.
If you are on Drupal 6 have a look into the node_counter table where there could be a older value.
When executing the following mysql query, do you have a result?
SELECT * FROM node WHERE nid = 308;

How to query the number of view counts for a post in Wordpress JetPack?

I use JetPack stats to follow the stats for my blog. I would like to extract the top 10 most-viewed posts for a given period (e.g. last month).
I used the WordPress stats plugin API before which worked nicely, but after upgrade to JetPack this doesn't work anymore.
Is there an API which allows me to query the number of view counts for a post?
Inside the Database
This option is recorded in the database and is used by the Dashboard widget:
get_option( 'stats_cache' );
It returns an array like this:
array(
['7375996b7a989f95a6ed03ca7c899b1f'] => array(
[1353440532] => array(
[0] => array(
['post_id'] => 0
['post_title'] => 'Home page'
['post_permalink'] => 'http://www.example.com/'
['views'] => 1132
)
[1] => array(
['post_id'] => 4784
['post_title'] => 'Hello World!'
['post_permalink'] =>
['views'] => 493
)
/* till item [9] */
Querying WordPress.com
It is possible to call the following Jetpack function:
if( function_exists( 'stats_get_csv' ) ) {
$top_posts = stats_get_csv( 'postviews', 'period=month&limit=30' );
}
Which returns:
array(
[0] => array(
['post_id'] => 0
['post_title'] => 'Home page'
['post_permalink'] => 'http://www.example.com/'
['views'] => 6806
)
[1] => array(
['post_id'] => 8005
['post_title'] => 'Hello World!'
['post_permalink'] =>
['views'] => 1845
)
/* till item [29] */
Function get_stats_csv
/plugins/jetpack/modules/stats.php
The function get_stats_csv calls http://stats.wordpress.com/csv.php. If we visit this address, we get this response:
Error: api_key is a required parameter.
Required parameters: api_key, blog_id or blog_uri.
Optional parameters: table, post_id, end, days, limit, summarize.
Parameters:
api_key String A secret unique to your WordPress.com user account.
blog_id Integer The number that identifies your blog.
Find it in other stats URLs.
blog_uri String The full URL to the root directory of your blog.
Including the full path.
table String One of views, postviews, referrers, referrers_grouped,
searchterms, clicks, videoplays.
post_id Integer For use with postviews table.
end String The last day of the desired time frame.
Format is 'Y-m-d' (e.g. 2007-05-01)
and default is UTC date.
days Integer The length of the desired time frame.
Default is 30. "-1" means unlimited.
period String For use with views table and the 'days' parameter.
The desired time period grouping. 'week' or 'month'
Use 'days' as the number of results to return
(e.g. '&period=week&days=12' to return 12 weeks)
limit Integer The maximum number of records to return.
Default is 100. "-1" means unlimited.
If days is -1, limit is capped at 500.
summarize Flag If present, summarizes all matching records.
format String The format the data is returned in,
'csv', 'xml' or 'json'.
Default is 'csv'.
Non-working query example:
?api_key=123456789abc&blog_id=155&table=referrers&days=30&limit=-1&summarize
Result format is csv with one row per line and column names in first row.
Strings containing double quotes, commas, or "\n" are enclosed in double-quotes.
Double-qoutes in strings are escaped by inserting another double-quote.
Example: "pet food" recipe
Becomes: """pet food"" recipe"
Developers, please cache the results for at least 180 seconds.

Views relationship with multiple files

I have a content types with 3 file fields, all of them can have an unlimited number of images. I need to make a view that returns the title of the content and the images name inside an array (I'm using amfphp with services). The problem is that when I add the relationship to the content field_pics fid I get as many duplicate nodes as the number of the images in the field:
EG:
[10] => stdClass Object
(
[nid] => 56
[node_title] => asd asd asd
[node_language] =>
[node_nid] => 56
)
[11] => stdClass Object
(
[nid] => 56
[node_title] => asd asd asd
[node_language] =>
[node_nid] => 56
)
This is the query:
SELECT node.nid AS nid, node.title AS node_title, node.language AS node_language, node.nid AS node_nid
FROM node node
LEFT JOIN content_field_colori node_data_field_colori ON node.vid = node_data_field_colori.vid
LEFT JOIN files files_node_data_field_colori ON node_data_field_colori.field_colori_fid = files_node_data_field_colori.fid
WHERE (node.status <> 0 OR (node.uid = ***CURRENT_USER*** AND ***CURRENT_USER*** <> 0) OR ***ADMINISTER_NODES*** = 1) AND (node.type in ('prodotto'))
ORDER BY node_nid ASC
I don't know how to fix this.
ANy help is appreciated.
Thanks
I think I understand what you're trying to do now. Unfortunately, Services's views support isn't all that great when it comes to CCK. There are a lot of different issues (e.g. one, two, three) with a lot of different patches and comments, but based on my understanding, to capture what you want is to not use relationships and to use the Node row style. If you use relationships, you get the output you're seeing, and if you use the Fields row style, the ImageField fields never load.

Resources