Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • Framadate Framadate
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 256
    • Issues 256
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 53
    • Merge requests 53
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Commits
  • Issue Boards
Collapse sidebar
  • FramasoftFramasoft
  • FramadateFramadate
  • FramadateFramadate
  • Issues
  • #510
Closed
Open
Issue created May 15, 2020 by Maschinenraum@maschinenraum

PollRepository: FindAll mising DateTime creating (Admin Polls)

When visiting the /admin/polls.php I receive the following error while displaying the first element. After the column Expiry Date nothing is displayed.

Fatal error: Uncaught TypeError: Argument 1 passed to smarty_modifier_date_format_intl() must be an instance of DateTime or null, string given, called in /var/www/framadate/tpl_c/d808313ab2d98debbca31f5e2b2afa66614bb293_0.file.polls.tpl.php on line 206 and defined in /var/www/framadate/app/inc/smarty.php:134 Stack trace: #0 /var/www/framadate/tpl_c/d808313ab2d98debbca31f5e2b2afa66614bb293_0.file.polls.tpl.php(206): smarty_modifier_date_format_intl('2020-10-12 19:4...', 'd/m/Y') #1 /var/www/framadate/vendor/smarty/smarty/libs/sysplugins/smarty_internal_runtime_inheritance.php(248): Block_354260935ebecf2c1fd233_67430546->callBlock(Object(Smarty_Internal_Template)) #2 /var/www/framadate/vendor/smarty/smarty/libs/sysplugins/smarty_internal_runtime_inheritance.php(184): Smarty_Internal_Runtime_Inheritance->callBlock(Object(Block_354260935ebecf2c1fd233_67430546), Object(Smarty_Internal_Template)) #3 /var/www/framadate/vendor/smarty/smarty/libs/sysplugins/smarty_internal_runtime_inheritance.php(186): Smarty_Internal_Runtime_Inhe in /var/www/framadate/app/inc/smarty.php on line 134

My Database table fd_poll looks this. The current migration 20191111110000 is applied.

+----------------------------+--------------+------+-----+---------------------+-------+
| Field                      | Type         | Null | Key | Default             | Extra |
+----------------------------+--------------+------+-----+---------------------+-------+
| id                         | varchar(64)  | NO   | PRI | NULL                |       |
| admin_id                   | varchar(255) | NO   |     | NULL                |       |
| title                      | longtext     | NO   |     | NULL                |       |
| description                | longtext     | YES  |     | NULL                |       |
| admin_name                 | varchar(255) | NO   |     | NULL                |       |
| admin_mail                 | varchar(255) | YES  |     | NULL                |       |
| creation_date              | datetime     | NO   |     | 2020-05-15 19:16:13 |       |
| end_date                   | datetime     | YES  |     | NULL                |       |
| format                     | varchar(255) | YES  |     | NULL                |       |
| editable                   | int(11)      | NO   |     | 0                   |       |
| receiveNewVotes            | tinyint(1)   | NO   |     | 0                   |       |
| active                     | tinyint(1)   | NO   |     | 1                   |       |
| receiveNewComments         | tinyint(1)   | NO   |     | 0                   |       |
| hidden                     | tinyint(1)   | NO   |     | 0                   |       |
| password_hash              | varchar(255) | YES  |     | NULL                |       |
| results_publicly_visible   | tinyint(1)   | YES  |     | NULL                |       |
| ValueMax                   | smallint(6)  | YES  |     | NULL                |       |
| collect_users_mail         | tinyint(1)   | NO   |     | 0                   |       |
| collect_users_mail_integer | smallint(6)  | NO   |     | 0                   |       |
| value_max                  | smallint(6)  | YES  |     | NULL                |       |
+----------------------------+--------------+------+-----+---------------------+-------+

I tracked down the issue to following template

                            {if $poll->end_date > date_create()}
                                <td>{$poll->end_date|date_format_intl:'d/m/Y'}</td>
                            {else}
                                <td><span class="text-danger">{$poll->end_date|date_format_intl:'d/m/Y'}</span></td>
                            {/if}

https://framagit.org/framasoft/framadate/framadate/-/blob/develop/tpl/admin/polls.tpl#L96-100

And the corresponding function:

function date_format_intl(?DateTime $date, $pattern = DATE_FORMAT_FULL, $forceLocale = null) {
    global $locale;
    $local_locale = $forceLocale ?? $locale;
    $date = $date ?? new DateTime();

    $dateFormatter = IntlDateFormatter::create(
        $local_locale,
        IntlDateFormatter::FULL,
        IntlDateFormatter::FULL,
        date_default_timezone_get(),
        IntlDateFormatter::GREGORIAN,
        $pattern
    );
    return $dateFormatter->format($date);
}

https://framagit.org/framasoft/framadate/framadate/-/blob/develop/app/inc/i18n.php#L52

It seems like the Convertion from String to DateTime, which is done for findById, is missing for the findAll function:

/**
         * Hack to make date a proper DateTime
         */
        $poll->creation_date = Type::getType(Type::DATETIME)->convertToPhpValue($poll->creation_date, $this->connect->getDatabasePlatform());
        $poll->end_date = Type::getType(Type::DATETIME)->convertToPhpValue($poll->end_date, $this->connect->getDatabasePlatform());

https://framagit.org/framasoft/framadate/framadate/-/blob/develop/app/classes/Framadate/Repositories/PollRepository.php#L57

FindAll https://framagit.org/framasoft/framadate/framadate/-/blob/develop/app/classes/Framadate/Repositories/PollRepository.php#L159

I suggest, that either the template is adjusted or the DateTime creation is done for all Items in the findAll function.

// app/classes/Framadate/Repositories/PollRepository.php
205         $polls = $prepared->fetchAll();
206 
207         foreach ($polls as &$poll) {
208             $poll->creation_date = Type::getType(Type::DATETIME)->convertToPhpValue($poll->creation_date, $this->connect->getDatabasePlatform());
209             $poll->end_date = Type::getType(Type::DATETIME)->convertToPhpValue($poll->end_date, $this->connect->getDatabasePlatform());
210         }
211 
212         return $polls;
Edited May 15, 2020 by Maschinenraum
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information
Assignee
Assign to
Time tracking