Problem/Motivation

The date_api.module file is about 2000 lines long and hard to navigate and maintain.

Steps to reproduce

Proposed resolution

Reduce clutter a bit by moving DateObject into a separate file. It is not a hook_* and should not need to be located there.

Remaining tasks

None.

User interface changes

None.

API changes

None.

Data model changes

None.

Comments

steinmb created an issue. See original summary.

steinmb’s picture

Status: Active » Needs review
StatusFileSize
new63.81 KB

Status: Needs review » Needs work

The last submitted patch, 2: date-3019527-refactor_date_api-1.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

steinmb’s picture

Status: Needs work » Needs review
StatusFileSize
new63.84 KB

Placed the new includes directory in the wrong module directory. This put it inside Date API directory. Let us try this one more time then.

Status: Needs review » Needs work

The last submitted patch, 4: date-3019527-refactor_date_api-2.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

steinmb’s picture

Not sure about the failing test. DateNowUnitTestCase extends DrupalUnitTestCase - It does not create/use a db. nor file - https://api.drupal.org/api/drupal/modules%21simpletest%21drupal_web_test... and I cannot re-produce it locally.

steinmb’s picture

Status: Needs work » Needs review
StatusFileSize
new64.24 KB
new403 bytes

Since I am unable to re-produce locally do I just have to guess. Perhaps https://api.drupal.org/api/drupal/includes%21bootstrap.inc/function/drup... get called and then It try to use the registry to autoload the Class?

steinmb’s picture

StatusFileSize
new32.46 KB

Patch reroll

Status: Needs review » Needs work

The last submitted patch, 8: date-3019527-refactor_date_api-8.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

steinmb’s picture

Status: Needs work » Needs review
StatusFileSize
new64.21 KB

Doh, wrong patch.

steinmb’s picture

Title: Refacactor Date API - Move DateObject class to an separate file » Move DateObject class to an separate file
Issue summary: View changes
StatusFileSize
new64.88 KB

Updated IS. Manual re-roll. Lets see if we broke something. Lots of tests and test-structure have changed since I originally rolled this but this change is as small as possible, move the class out, no other changes.

Status: Needs review » Needs work

The last submitted patch, 11: date-3019527-11.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

steinmb’s picture

Status: Needs work » Needs review
StatusFileSize
new65.32 KB
new447 bytes

No, it looks like test-bot fail the same place as 3 years ago (#6). @DamienMcKenna you might know why this is?
Adding back the fix from #7 but I am not sure I like it.

damienmckenna’s picture

If you look at the docs for drupal_load() it only loads the main file for that item - it doesn't load the full module's dependencies, include files or anything else. So this is by design. It might be cleaner to move the manual require_once() to after the drupal_load() and to document the issue there, so others will know why it's written this way.

steinmb’s picture

StatusFileSize
new757 bytes
new65.5 KB

You are right. Looking at DrupalUnitTestCase:setUp() have actually document this:

  /**
   * Sets up unit test environment.
   *
   * Unlike DrupalWebTestCase::setUp(), DrupalUnitTestCase::setUp() does not
   * install modules because tests are performed without accessing the database.
   * Any required files must be explicitly included by the child class setUp()
   * method.
   */

Does not this mean that we do no not need the drupal_load() ? - Unit tests locally worked just fine without it.

Status: Needs review » Needs work

The last submitted patch, 15: date-3019527-15.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

steinmb’s picture

Status: Needs work » Needs review
StatusFileSize
new65.48 KB

Oh well, test bot seems to need it for something...

steinmb’s picture

Version: 7.x-2.x-dev » 7.x-3.x-dev
Status: Needs review » Needs work

I can re-roll this for 7.x-3.x if there is any interest getting this housekeeping change in?

damienmckenna’s picture

Ultimately yes I'd like to include this change, a reroll would be appreciated. Thank you.

solideogloria’s picture

Status: Needs work » Needs review
StatusFileSize
new33.29 KB

Rerolled for 3.x. Please review and test.

solideogloria’s picture

StatusFileSize
new33.31 KB

Fix tests.

require_once './' . drupal_get_path('module', 'date_api') . '/includes/DateObject.php';

solideogloria’s picture

Status: Needs review » Needs work

I don't know why it can't open the file... anybody know what's wrong?

damienmckenna’s picture

Your patches are missing the new file.

solideogloria’s picture

Status: Needs work » Needs review
StatusFileSize
new65.65 KB

D'oh. I added the file.

  • DamienMcKenna committed 700c1d8 on 7.x-3.x
    Issue #3019527 by steinmb, solideogloria, DamienMcKenna: Move DateObject...
damienmckenna’s picture

Status: Needs review » Fixed

Thanks!

damienmckenna’s picture

solideogloria’s picture

Status: Fixed » Needs work

I forgot about this quirk, but after updating I get

Error: Class 'DateObject' not found in date_views_filter_handler_simple->op_simple() (line 219 of /var/www/dcc-staging/sites/all/modules/contrib/date/date_views/includes/date_views_filter_handler_simple.inc).

A cache clear (in an update hook) is required to fix the issue.

damienmckenna’s picture

Did you not clear the caches after updating the site to alpha2? I can just update the release notes and leave it at that, it's just an alpha release so that's sufficient for now imho.

solideogloria’s picture

Status: Needs work » Fixed

Mmk.

damienmckenna’s picture

Thanks for being through, I do appreciate it.

solideogloria’s picture

I have no idea what caused it, but when I merged alpha2 into my project, I received this error:

Error: Call to undefined function date_make_iso_valid() in DateObject->__construct() (line 130 of /var/www/html/sites/all/modules/contrib/date/date_api/includes/DateObject.

However, clearing cache and registry rebuild had already been performed. The error also only happened for me in a non-private browsing window on my current device. I had to clear my browser's cache to fix it.

I doubt there's anything that needs to be done in code. I just wanted to post this here in case someone else has the same issue. I only had it for one branch, too. I had tested it successfully in dev/staging, so there's no way I can reproduce it.

damienmckenna’s picture

Thanks for the extra details. That is weird. I've ran into occasional problems with what appears to be the nfs connection in ddev not quite working correctly and an old file getting "stuck", it didn't fix itself until I restarted ddev.

solideogloria’s picture

Status: Fixed » Needs work

I found a way to reproduce the error reliably. Once I view a certain page, the entire site becomes unviewable (for only me) until I clear my browser's cache.

I'm going to reopen this issue and begin posting debug information I discover.

solideogloria’s picture

Note that this error is different than the other one I shared above, but this is the one that is showing and reproduceable.

Fatal error: Uncaught Error: Call to undefined function date_limit_format() in /var/www/html/sites/all/modules/contrib/date/date_api/includes/DateObject.php on line 271

1	31.3130	3267656	_drupal_shutdown_function( )	.../bootstrap.inc:0
2	31.3131	3267576	session_write_close( )	.../bootstrap.inc:3856
3	31.3131	3267896	DateObject->__sleep( )	.../bootstrap.inc:3856
4	32.8765	3267896	DateObject->format( $format = 'c', $force = ??? )  # $force is FALSE here

I also get this (This is due to a bootstrap error, I realized):

Error: Call to undefined function menu_get_object() in /var/www/html/includes/theme.inc on line 2619

Basically, I get ONE view of the page in question, and after I view it once, viewing any page on the site will throw the above fatal errors. The page in question is a view. My guess is that something gets saved to the session, (I saw stuff about views filters, I think, perhaps remembering which ones are selected?), and once that happens, it cannot be unserialized when loading the session?

Is it possible that the DateObject class is not properly (un)serializable?

solideogloria’s picture

Relevant code:

  /**
   * Prepares the object during serialization.
   *
   * We are extending a core class and core classes cannot be serialized.
   *
   * @return array
   *   Returns an array with the names of the variables that were serialized.
   *
   * @see http://bugs.php.net/41334
   * @see http://bugs.php.net/39821
   */
  public function __sleep() {
    $this->serializedTime = $this->format('c');
    $this->serializedTimezone = $this->getTimezone()->getName();
    return array('serializedTime', 'serializedTimezone');
  }

...

  #[\ReturnTypeWillChange]
  public function format($format, $force = FALSE) {
    return parent::format($force ? $format : date_limit_format($format, $this->granularity));
  }
solideogloria’s picture

I placed a breakpoint earlier, and I confirmed my suspicions, as the root exception being thrown is:

"Invalid serialization data for DateTime object"

I tried removing the serialization code from DateObject, and I no longer experience the problem. The code itself says this:

   * We are extending a core class and core classes cannot be serialized.
   ...
   * @see http://bugs.php.net/41334
   * @see http://bugs.php.net/39821

But looking at the linked PHP bugs, built-in PHP objects are serializable as of PHP 5.3. Since we don't need to support < PHP 5.3, I'm going to recommend that we remove this code and use the native serialization. I'll create a separate issue and link it here.

solideogloria’s picture

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.