-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Warning: date_timezone_set() expects parameter 1 to be DateTime #1
Comments
Here is the backtrace:
|
I've traced the error to the line:
in the
|
So changing the #markup line to:
takes care of the error. |
Thanks for working on this @AlexShapka 👍 ...is
/**
* @param string $string
* @return bool
*/
public function isTimestamp($string)
{
try {
new DateTime('@' . $string);
} catch(Exception $e) {
return false;
}
return true;
} I'm even keen on adding this as a helper function in Backdrop core for better DX (so that we can reuse it in other contrib and in core). |
...perhaps we can even do something like |
I believe it is always timestamp, however the problem here is that when there was no any reset yet, then the line #61 of the file:
returns the I am not sure what is the ideal solution here, but I thought that since the |
Here's what I think we should do: $reset_date = config_get('demo.settings', 'demo_reset_last');
// @todo: change this check to use is_valid_timestamp().
// See https://github.com/backdrop/backdrop-issues/issues/4132
try {
// Prepending '@' as the $time parameter denotes UNIX timestamp.
$reset_date = new DateTime('@' . $reset_date);
}
catch(Exception $e) {
$reset_date = FALSE;
}
$form['status']['reset_last'] = array(
'#type' => 'item',
'#title' => t('Last reset'),
'#markup' => $reset_date ? format_date($reset_date) : t('Never'),
); Once we have a proper $reset_date = config_get('demo.settings', 'demo_reset_last');
$form['status']['reset_last'] = array(
'#type' => 'item',
'#title' => t('Last reset'),
'#markup' => is_valid_timestamp($reset_date) ? format_date($reset_date) : t('Never'),
); Then we should create a new release of the module, and specify |
How about: $reset_date = config_get('demo.settings', 'demo_reset_last');
// @todo: change this check to use is_valid_timestamp().
// See https://github.com/backdrop/backdrop-issues/issues/4132
try {
// Prepending '@' as the $time parameter denotes UNIX timestamp.
$reset_date = new DateTime('@' . $reset_date);
}
catch(Exception $e) {
$message = t("<strong>Error:</strong> @message <br>", array('@message' => $e->getMessage()));
$message .= t("<strong>File:</strong> @file <br>", array('@file' => $e->getFile()));
$message .= t("<strong>Line:</strong> @line", array('@line' => $e->getLine()));
watchdog('PHP', $message, array(), $e->severity);
$reset_date = FALSE;
} ? This way it gives nice and informative message like so: |
@klonos I believe introducing the function for catching exceptions to core as you suggested could be really useful tool for easier troubleshooting the errors. However, for this particular case we might want to retreat and come up with the different solution. The API page for the
So provided no any snapshot executed yet, it was supposed to return NULL, however we always have the {
"_config_name": "demo.settings",
"demo_dump_path": "demo",
"demo_reset_last": "novalue",
"demo_reset_interval": "novalue",
"demo_dump_cron": "demo_site"
} and also in the /**
* Implements hook_update_N().
*/
function demo_update_1000() {
$config = config('demo.settings');
$config->set('demo_dump_path', update_variable_get('demo_dump_path', 'demo'));
$config->set('demo_reset_last', update_variable_get('demo_reset_last', 'novalue'));
$config->set('demo_reset_interval', update_variable_get('demo_reset_interval', 'novalue'));
$config->set('demo_dump_cron', update_variable_get('demo_dump_cron', 'demo_site'));
update_variable_del('demo_dump_path');
update_variable_del('demo_reset_last');
update_variable_del('demo_reset_interval');
update_variable_del('demo_dump_cron');
} So maybe the right way of fixing this issue, would be not setting any value for What do you think? |
New PR with clean solution created on #4 |
Thanks for working on this @AlexShapka 👍 ...I have merged this change, but please see my comment in the PR re update hooks (for future reference). |
...I still think that we should address the core issue in backdrop/backdrop-issues#4132 in a way that benefits core and contrib. |
Enabling this module and going to
admin/structure/demo
gives:The text was updated successfully, but these errors were encountered: