Support from Acquia helps fund testing for Drupal Acquia logo

Comments

tzsl created an issue. See original summary.

mikeryan’s picture

Version: 8.2.1 » 8.2.x-dev
Issue tags: -Drupal 7 to Drupal 8 content migration +migrate-d7-d8
Related issues: +#2566779: Migration D6 > D8 of CCK date fields

The date stored there in D8 is actually wrong - the format is 2016-10-25T16:43:21. Looks like we need a process plugin to translate.

See also #2566779: Migration D6 > D8 of CCK date fields.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

kcolwell’s picture

If you need a quick fix for this problem until the bug is really fixed the code below will get things semi-working. It's not the right way to do this but it will convert the date to the correct format for drupal 8. My table name was node__field_eventstart and the column is field_eventstart_value. Change those in the code below to match your table and field. Backup your database first... then save this file as fix_date.php and run with the command line php fix_date.php.


$link = mysqli_connect("127.0.0.1", "user", "pass", "db_name");

if (!$link) {
    echo "Error: Unable to connect to MySQL." . PHP_EOL;
    echo "Debugging errno: " . mysqli_connect_errno() . PHP_EOL;
    echo "Debugging error: " . mysqli_connect_error() . PHP_EOL;
    exit;
}

$res = mysqli_query($link, "select entity_id, field_eventstart_value from node__field_eventstart");
while ($row = $res->fetch_assoc()) {
    echo $row['entity_id'] . " " . $row['field_eventstart_value']. "\n";
    $res2 = mysqli_query($link, "UPDATE node__field_eventstart dest, (select field_eventstart_value from node__field_eventstart where entity_id = ".$row['entity_id']." ) src SET dest.field_eventstart_value = DATE_FORMAT( src.field_eventstart_value, '%Y-%m-%dT%H:%i:%S') WHERE entity_id =".$row['entity_id']."");
}

mysqli_close($link);
tzsl’s picture

Thanks for your quick fix. I have update all the datefields.

irinaz’s picture

FileSize
11.26 KB

@mikeryan
Our team built process plugin to convert date (attache here, custom_migrate.zip). What is best way to package it so it can be tested and included in core?

mikeryan’s picture

Status: Active » Closed (duplicate)
Related issues: +#2820490: FormatDate process plugin
irinaz’s picture

Thanks for pointing me to the new thread! I will do testing and report results. Can I ask here - is there thread for converting longtext-plaintext format for drupal7 to text-plain,long in drupal8?
thanks!

mikeryan’s picture

@irinaz: I was a bit short in my previous reply, just threw that out there on my way out the door. For information on contributing to Drupal, the main resource is https://www.drupal.org/docs/develop. More specifically, for contributing patches to Drupal, see https://www.drupal.org/node/707484.

In terms of finding an existing issue, the issue queue is searchable - for example, https://www.drupal.org/project/issues/search/drupal?text=format&project_... searches for open migration system issues mentioning "format". In that list, #2842222: D7 Plain text fields incorrectly migrated to D8 as Text (formatted) may be what you're looking for.

irinaz’s picture

@mikeryan - thank you VERY much, it is the issue. Our team with try to contribute what we can to have both issues moved forward.

vpa24’s picture

Issue summary: View changes
$link = mysqli_connect("127.0.0.1", "user", "pass", "db_name");

if (!$link) {
    echo "Error: Unable to connect to MySQL." . PHP_EOL;
    echo "Debugging errno: " . mysqli_connect_errno() . PHP_EOL;
    echo "Debugging error: " . mysqli_connect_error() . PHP_E&lt;code&gt;</code>OL;
    exit;
}

$res = mysqli_query($link, "select entity_id, field_date_value from table");
while ($row = $res->fetch_assoc()) {
    echo $row['entity_id'] . " " . $row['field_date_value ']. "\n";
    $res2 = mysqli_query($link, "UPDATE table dest SET dest.field_date_value = DATE(STR_TO_DATE(field_date_value , '%Y-%m-%dT%H:%i:%S')) WHERE entity_id =".$row['entity_id']."");
}

mysqli_close($link);
cilefen’s picture

Issue summary: View changes

@vpa24 I restored the original issue summary. The meaning of the edit you made is not clear.

Ralkeon’s picture

Status: Closed (duplicate) » Active

Sorry guys, but I don't understand why this was closed as duplicate refering to a d6 > d8 issue.
Reopening this cause I'm facing the issue on d7 > d8 hoping it helps someone.

I've two field date on two different content types. One of them is working, the other one is not... I figured out that the one is working was set (in the configuration file in the sync folder) on datetime_type: datetime and the other one was datetime_type: date.

I used the code suggested above to change the format to date only and it worked!

basically I've changed this part:
DATE_FORMAT( src.field_eventstart_value, '%Y-%m-%dT%H:%i:%S')
to this:
DATE_FORMAT( src.field_eventstart_value, '%Y-%m-%d')

vpa24’s picture

This is my custom module can help fix date. You just go to admin/config/development/fix-date
https://github.com/vpa24/fix_date/

vpa24’s picture

FileSize
1.73 KB

This is my custom module can help fix date. You just go to admin/config/development/fix-date
https://github.com/vpa24/fix_date/

juampynr’s picture

juampynr’s picture

Version: 8.3.x-dev » 8.8.x-dev
Status: Active » Needs review
Issue tags: +Needs tests
FileSize
1.66 KB

Here is a patch without a test. Once applied, recreate migrations and you should get the right to_format for fields that have a granularity of just the date.

juampynr’s picture

Oops. I marked it as not to be tested. Uploading again.

Status: Needs review » Needs work

The last submitted patch, 18: drupal-datetime_empty-2822801-16.patch, failed testing. View results

juampynr’s picture

Status: Needs work » Needs review
FileSize
1.82 KB
408.05 KB

Here is an updated patch that should fix the multiple test warnings.

juampynr’s picture

Here I have extended test coverage. This is the coverage report for the class that I modified before this patch:

And here is using this patch:

Status: Needs review » Needs work

The last submitted patch, 21: drupal-datetime_empty-2822801-21.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

juampynr’s picture

Status: Needs work » Needs review
FileSize
6.46 KB

This patch adds an adjustment to core/modules/datetime/tests/src/Unit/Plugin/migrate/field/DateFieldLegacyTest.php so tests pass.

quietone’s picture

ON a very brief look, the change here looks similar to what is done in #3007102: Migrating to Date-only field does not drop time value. What is the difference?

juampynr’s picture

Yeah, it seems the same bug @quietone, just that I am testing the class differently.

Feel free to mark this one as a duplicate if you consider it fit.

quietone’s picture

Status: Needs review » Needs work

@juampynr, thanks that helped. I don't see similar tests in the other issue so let move the tests here over to #3007102: Migrating to Date-only field does not drop time value. Once that is done this can be marked as a duplicate.

mikelutz’s picture

Status: Needs work » Closed (duplicate)

I've merged the explicit unit tests from here into #3007102: Migrating to Date-only field does not drop time value and am closing this as a duplicate.
@juampynr is already credited on that issue, and I've transferred @vpa24's credit over there as well.