Skip to content
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

PR 546 - Avoid session invalidation when changing session lifetime - kills my deployment #2212

Closed
iamniels opened this issue Jun 11, 2022 · 5 comments · Fixed by #2221
Closed

Comments

@iamniels
Copy link
Contributor

PR #546 kills my deployment.

"SQLSTATE[42S22]: Column not found: 1054 Unknown column 'password_created_at' in 'field list', query was: SELECT IFNULL(password_created_at, created_at) AS `password_created_at` FROM `customer_entity` WHERE (entity_id =958)";i:1;s:2531:"#0 /var/www/lib/Varien/Db/Statement/Pdo/Mysql.php(110): Zend_Db_Statement_Pdo->_execute()
#1 /var/www/app/code/core/Zend/Db/Statement.php(291): Varien_Db_Statement_Pdo_Mysql->_execute()
#2 /var/www/lib/Zend/Db/Adapter/Abstract.php(480): Zend_Db_Statement->execute()
#3 /var/www/lib/Zend/Db/Adapter/Pdo/Abstract.php(238): Zend_Db_Adapter_Abstract->query()
#4 /var/www/lib/Varien/Db/Adapter/Pdo/Mysql.php(508): Zend_Db_Adapter_Pdo_Abstract->query()
#5 /var/www/lib/Zend/Db/Adapter/Abstract.php(828): Varien_Db_Adapter_Pdo_Mysql->query()
#6 /var/www/app/code/core/Mage/Customer/Model/Resource/Customer.php(381): Zend_Db_Adapter_Abstract->fetchOne()
#7 /var/www/app/code/core/Mage/Customer/Helper/Data.php(753): Mage_Customer_Model_Resource_Customer->getPasswordTimestamp()
#8 /var/www/app/code/core/Mage/Core/Model/Session/Abstract/Varien.php(568): Mage_Customer_Helper_Data->getPasswordTimestamp()

The password_created_at column is indeed not present in the customer_entity table. password_created_at is however available as an EAV customer attribute.

Steps to reproduce (*)

  1. PHP 8.1 / MySQL 5.7
  2. Login as a customer and visit the store

Any ideas?

@iamniels iamniels added the bug label Jun 11, 2022
@addison74 addison74 changed the title PR Avoid session invalidation when changing session lifetime. #546 kills my deployment PR 546 - Avoid session invalidation when changing session lifetime - kills my deployment Jun 11, 2022
@fballiano
Copy link
Contributor

fballiano commented Jun 11, 2022

confirmed

SELECT IFNULL(password_created_at, created_at) AS `password_created_at` FROM `customer_entity` WHERE (entity_id ='3')

@colinmollenhour there's actually nothing that creates and populates that password_created_at column, but maybe should be just an alias?

@fballiano
Copy link
Contributor

so, password_created_at it's a customer attribute, but it's not in the customer_entity table as used by #546

@kiatng
Copy link
Contributor

kiatng commented Jun 12, 2022

Can you see if the following patch for file app\code\core\Mage\Customer\Model\Resource\Customer.php works:

    /**
     * Get password created at timestamp for a customer by id
     *
     * @param int $customerId
     * @return int|false
     */
    public function getPasswordTimestamp($customerId)
    {
        $field = $this->_getReadAdapter()->getIfNullSql('t2.value', 't0.created_at');
        $select = $this->_getReadAdapter()->select()
            ->from(['t0' => $this->getEntityTable()], ['password_created_at' => $field])
            ->joinLeft(
                ['t1' => $this->getTable('eav/attribute')],
                't0.entity_type_id = t1.entity_type_id',
                []
            )
            ->joinLeft(
                ['t2' => $this->getTable(['customer/entity', 'datetime'])],
                't1.attribute_id = t2.attribute_id',
                []
            )
            ->where('t0.entity_id = ?', $customerId)
            ->where('t1.attribute_code = ?', 'password_created_at');
            
        $value = $this->_getReadAdapter()->fetchOne($select);
        if ($value && !is_numeric($value)) { // Convert created_at string to unix timestamp
            $value = Varien_Date::toTimestamp($value);
        }
        return $value;
    }

@iamniels
Copy link
Contributor Author

iamniels commented Jun 12, 2022

Can you see if the following patch for file app\code\core\Mage\Customer\Model\Resource\Customer.php works:

This has resolved the issue.

kiatng added a commit to kiatng/magento-lts that referenced this issue Jun 13, 2022

Verified

This commit was signed with the committer’s verified signature.
truthbk Jaime Fullaondo
…nown column 'password_created_at' in 'field list'
@colinmollenhour
Copy link
Member

Apologies @iamniels and others.. it never occurred to me that such an attribute would be an EAV attribute rather than a static column.. :(
Thanks for the fix, @kiatng !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants