Skip to content

User: Remove user.registration_date #6045 #6059

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

Merged
merged 1 commit into from
Feb 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions public/main/admin/statistics/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -747,7 +747,7 @@
$extraConditions = '';
if (!empty($startDate) && !empty($endDate)) {
// $extraConditions is already cleaned inside the function getUserListExtraConditions
$extraConditions .= " AND registration_date BETWEEN '$startDate' AND '$endDate' ";
$extraConditions .= " AND created_at BETWEEN '$startDate' AND '$endDate' ";
}

$totalCount = UserManager::getUserListExtraConditions(
Expand Down Expand Up @@ -856,7 +856,7 @@
$item = [];
$item[] = $user['firstname'];
$item[] = $user['lastname'];
$item[] = api_get_local_time($user['registration_date']);
$item[] = api_get_local_time($user['created_at']);
$item[] = $userLanguage;
$item[] = $languageTarget;
$item[] = $contract ? get_lang('Yes') : get_lang('No');
Expand Down
4 changes: 2 additions & 2 deletions public/main/admin/user_edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ function confirmation(name) {
$user_data['old_password'] = $user_data['password'];
//Convert the registration date of the user

$user_data['registration_date'] = api_get_local_time($user_data['registration_date']);
$user_data['created_at'] = api_get_local_time($user_data['created_at']);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Variable "user_data" is not in valid camel caps format

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Variable "user_data" is not in valid camel caps format

unset($user_data['password']);

// Create the form
Expand Down Expand Up @@ -288,7 +288,7 @@ function confirmation(name) {
get_lang('Create by <a href="%s">%s</a> on %s'),
'user_information.php?user_id='.$user_data['creator_id'],
$creatorInfo['username'],
$user_data['registration_date']
$user_data['created_at']

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Variable "user_data" is not in valid camel caps format

);
$form->addElement('label', get_lang('Registration date'), $date);
}
Expand Down
2 changes: 1 addition & 1 deletion public/main/admin/user_export.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@
u.status AS Status,
u.official_code AS OfficialCode,
u.phone AS Phone,
u.registration_date AS RegistrationDate";
u.created_at AS CreatedAt";
if (strlen($course_code) > 0) {
$sql .= " FROM $user_table u, $course_user_table cu
WHERE
Expand Down
4 changes: 2 additions & 2 deletions public/main/admin/user_information.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,12 +166,12 @@
$creatorId = $user->getCreatorId();
$creatorInfo = api_get_user_info($creatorId);
if (!empty($creatorId) && !empty($creatorInfo)) {
$registrationDate = $user->getRegistrationDate()->format('Y-m-d H:i:s');
$createdAt = $user->getCreatedAt()->format('Y-m-d H:i:s');
$userInfo['created'] = sprintf(
get_lang('Create by <a href="%s">%s</a> on %s'),
'user_information.php?user_id='.$creatorId,
$creatorInfo['username'],
api_get_utc_datetime($registrationDate)
api_get_utc_datetime($createdAt)
);
}

Expand Down
2 changes: 1 addition & 1 deletion public/main/admin/user_list.php
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ function prepare_user_sql_query(bool $getCount, bool $showDeletedUsers = false):
u.email AS col6,
u.status AS col7,
u.active AS col8,
u.registration_date AS col9,
u.created_at AS col9,
u.last_login as col10,
u.id AS col11,
u.expiration_date AS exp,
Expand Down
2 changes: 1 addition & 1 deletion public/main/admin/user_list_consent.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ function prepare_user_sql_query($getCount)
u.status AS col7,
u.active AS col8,
u.id AS col9,
u.registration_date AS col10,
u.created_at AS col10,
u.expiration_date AS exp,
u.password,
v.field_id,
Expand Down
2 changes: 1 addition & 1 deletion public/main/inc/ajax/statistics.ajax.php
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@

$extraConditions = '';
if (!empty($startDate) && !empty($endDate)) {
$extraConditions .= " AND registration_date BETWEEN '$startDate' AND '$endDate' ";
$extraConditions .= " AND created_at BETWEEN '$startDate' AND '$endDate' ";
}

switch ($filter) {
Expand Down
6 changes: 3 additions & 3 deletions public/main/inc/lib/api.lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -1321,7 +1321,7 @@ function _api_format_user($user, $add_password = false, $loadAvatars = true)
'language',
'locale',
'creator_id',
'registration_date',
'created_at',
'hr_dept_id',
'expiration_date',
'last_login',
Expand Down Expand Up @@ -1650,7 +1650,7 @@ function api_get_user_info_from_entity(
$result['auth_source'] = $user->getAuthSource();
$result['language'] = $user->getLocale();
$result['creator_id'] = $user->getCreatorId();
$result['registration_date'] = $user->getRegistrationDate()->format('Y-m-d H:i:s');
$result['created_at'] = $user->getCreatedAt()->format('Y-m-d H:i:s');
$result['hr_dept_id'] = $user->getHrDeptId();
$result['expiration_date'] = '';
if ($user->getExpirationDate()) {
Expand Down Expand Up @@ -1989,7 +1989,7 @@ function api_get_anonymous_id()
$result = Database::query($sql);
if (empty(Database::num_rows($result))) {
$login = uniqid('anon_');
$anonList = UserManager::get_user_list(['status' => ANONYMOUS], ['registration_date ASC']);
$anonList = UserManager::get_user_list(['status' => ANONYMOUS], ['created_at ASC']);
if (count($anonList) >= $max) {
foreach ($anonList as $userToDelete) {
UserManager::delete_user($userToDelete['user_id']);
Expand Down
6 changes: 3 additions & 3 deletions public/main/inc/lib/statistics.lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -1585,9 +1585,9 @@ public static function getLoginsByDate(string $startDate, string $endDate): arra
*/
public static function getNewUserRegistrations(string $startDate, string $endDate): array
{
$sql = "SELECT DATE_FORMAT(registration_date, '%Y-%m-%d') as reg_date, COUNT(*) as user_count
$sql = "SELECT DATE_FORMAT(created_at, '%Y-%m-%d') as reg_date, COUNT(*) as user_count
FROM user
WHERE registration_date BETWEEN '$startDate' AND '$endDate'
WHERE created_at BETWEEN '$startDate' AND '$endDate'
GROUP BY reg_date";

$result = Database::query($sql);
Expand All @@ -1608,7 +1608,7 @@ public static function getUserRegistrationsByCreator(string $startDate, string $
$sql = "SELECT u.creator_id, COUNT(u.id) as user_count, c.firstname, c.lastname
FROM user u
LEFT JOIN user c ON u.creator_id = c.id
WHERE u.registration_date BETWEEN '$startDate' AND '$endDate'
WHERE u.created_at BETWEEN '$startDate' AND '$endDate'
AND u.creator_id IS NOT NULL
GROUP BY u.creator_id";

Expand Down
5 changes: 2 additions & 3 deletions public/main/inc/lib/usermanager.lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,6 @@ public static function create_user(
->setPhone($phone)
->setAddress($address)
->setLocale($language)
->setRegistrationDate($now)
->setHrDeptId($hrDeptId)
->setActive($active)
->setTimezone(api_get_timezone())
Expand Down Expand Up @@ -3410,11 +3409,11 @@ public static function get_number_of_users(

if (!empty($dateFrom)) {
$dateFrom = api_get_utc_datetime("$dateFrom 00:00:00");
$sql .= " AND u.registration_date >= '$dateFrom' ";
$sql .= " AND u.created_at >= '$dateFrom' ";
}
if (!empty($dateUntil)) {
$dateUntil = api_get_utc_datetime("$dateUntil 23:59:59");
$sql .= " AND u.registration_date <= '$dateUntil' ";
$sql .= " AND u.created_at <= '$dateUntil' ";
}

$res = Database::query($sql);
Expand Down
4 changes: 2 additions & 2 deletions public/main/inc/lib/webservices/Rest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1876,8 +1876,8 @@ public function updateUserFromUserName($parameters)
}
$user->setLocale($value);
break;
case 'registration_date':
$user->setRegistrationDate($value);
case 'created_at':
$user->setCreatedAt($value);
break;
case 'expiration_date':
$user->setExpirationDate(
Expand Down
4 changes: 2 additions & 2 deletions public/main/inc/lib/zombie/zombie_manager.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public static function listZombies(
$column = 'firstname';
}

$validColumns = ['id', 'official_code', 'firstname', 'lastname', 'username', 'auth_source', 'email', 'status', 'registration_date', 'active', 'login_date'];
$validColumns = ['id', 'official_code', 'firstname', 'lastname', 'username', 'auth_source', 'email', 'status', 'created_at', 'active', 'login_date'];
if (!in_array($column, $validColumns)) {
$column = 'firstname';
}
Expand All @@ -60,7 +60,7 @@ public static function listZombies(
user.auth_source,
user.email,
user.status,
user.registration_date,
user.created_at,
user.active,
access.login_date';

Expand Down
2 changes: 1 addition & 1 deletion public/main/inc/lib/zombie/zombie_report.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ public function get_data($from, $count, $column, $direction)
$row[] = $item['email'];
$row[] = $item['status'];
$row[] = $item['auth_source'];
$row[] = api_format_date($item['registration_date'], DATE_FORMAT_SHORT);
$row[] = api_format_date($item['created_at'], DATE_FORMAT_SHORT);
$row[] = api_format_date($item['login_date'], DATE_FORMAT_SHORT);
$row[] = $item['active'];
$result[] = $row;
Expand Down
2 changes: 1 addition & 1 deletion public/main/tracking/lp_report.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ function prepare_user_sql_query($getCount)
u.email AS col6,
u.status AS col7,
u.active AS col8,
u.registration_date AS col9,
u.created_at AS col9,
u.last_login as col10,
u.id AS col11,
u.expiration_date AS exp,
Expand Down
2 changes: 1 addition & 1 deletion public/main/user/user_export.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
u.status AS Status,
u.official_code AS OfficialCode,
u.phone AS Phone,
u.registration_date AS RegistrationDate";
u.created_at AS RegistrationDate";
if (strlen($course_code) > 0) {
$sql .= " FROM $userTable u
INNER JOIN $course_user_table cu
Expand Down
6 changes: 3 additions & 3 deletions public/plugin/migrationmoodle/src/Loader/UsersLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,11 @@ public function load(array $incomingData)
throw new \Exception('User was not created');
}

if ($incomingData['registration_date']) {
$incomingData['registration_date'] = $incomingData['registration_date']->format('Y-m-d H:i:s');
if ($incomingData['created_at']) {
$incomingData['created_at'] = $incomingData['created_at']->format('Y-m-d H:i:s');

\Database::query(
"UPDATE $tblUser SET registration_date = '{$incomingData['registration_date']}' WHERE id = $userId"
"UPDATE $tblUser SET created_at = '{$incomingData['created_at']}' WHERE id = $userId"
);
}

Expand Down
2 changes: 1 addition & 1 deletion public/plugin/migrationmoodle/src/Task/UsersTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public function getTransformConfiguration()
'class' => AuthLookup::class,
'properties' => ['auth'],
],
'registration_date' => [
'created_at' => [
'class' => DateTimeObject::class,
'properties' => ['timecreated'],
],
Expand Down
21 changes: 0 additions & 21 deletions src/CoreBundle/Entity/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -615,9 +615,6 @@ class User implements UserInterface, EquatableInterface, ResourceInterface, Reso
#[ORM\Column(name: 'productions', type: 'string', length: 250, unique: false, nullable: true)]
protected ?string $productions = null;

#[ORM\Column(name: 'registration_date', type: 'datetime')]
protected DateTime $registrationDate;

#[ORM\Column(name: 'expiration_date', type: 'datetime', unique: false, nullable: true)]
protected ?DateTime $expirationDate = null;

Expand Down Expand Up @@ -759,7 +756,6 @@ public function __construct()
$this->logins = new ArrayCollection();
$this->createdAt = new DateTime();
$this->updatedAt = new DateTime();
$this->registrationDate = new DateTime();
$this->roles = [];
$this->credentialsExpired = false;
$this->credentialsExpireAt = new DateTime();
Expand Down Expand Up @@ -1045,18 +1041,6 @@ public function setProductions(?string $productions): self
return $this;
}

public function getRegistrationDate(): DateTime
{
return $this->registrationDate;
}

public function setRegistrationDate(DateTime $registrationDate): self
{
$this->registrationDate = $registrationDate;

return $this;
}

public function getExpirationDate(): ?DateTime
{
return $this->expirationDate;
Expand Down Expand Up @@ -1122,11 +1106,6 @@ public function setHrDeptId(int $hrDeptId): self
return $this;
}

public function getMemberSince(): DateTime
{
return $this->registrationDate;
}

public function isOnline(): bool
{
return false;
Expand Down
6 changes: 3 additions & 3 deletions src/CoreBundle/EventSubscriber/AnonymousUserSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public function onKernelRequest(RequestEvent $event): void
'auth_source' => $user->getAuthSource(),
'theme' => $user->getTheme(),
'language' => $user->getLocale(),
'registration_date' => $user->getRegistrationDate()->format('Y-m-d H:i:s'),
'created_at' => $user->getCreatedAt()->format('Y-m-d H:i:s'),
'expiration_date' => $user->getExpirationDate() ? $user->getExpirationDate()->format('Y-m-d H:i:s') : null,
'last_login' => $user->getLastLogin() ? $user->getLastLogin()->format('Y-m-d H:i:s') : null,
'is_anonymous' => true,
Expand All @@ -98,7 +98,7 @@ private function getOrCreateAnonymousUserId(string $userIp): ?int
$anonymousAutoProvisioning = 'true' === $this->settingsManager->getSetting('security.anonymous_autoprovisioning');

if (!$anonymousAutoProvisioning) {
$anonymousUser = $userRepository->findOneBy(['status' => User::ANONYMOUS], ['registrationDate' => 'ASC']);
$anonymousUser = $userRepository->findOneBy(['status' => User::ANONYMOUS], ['createdAt' => 'ASC']);
if ($anonymousUser) {
return $anonymousUser->getId();
}
Expand All @@ -110,7 +110,7 @@ private function getOrCreateAnonymousUserId(string $userIp): ?int
if (0 === $maxAnonymousUsers) {
$maxAnonymousUsers = self::MAX_ANONYMOUS_USERS;
}
$anonymousUsers = $userRepository->findBy(['status' => User::ANONYMOUS], ['registrationDate' => 'ASC']);
$anonymousUsers = $userRepository->findBy(['status' => User::ANONYMOUS], ['createdAt' => 'ASC']);

// Check in TrackELogin if there is an anonymous user with the same IP
foreach ($anonymousUsers as $user) {
Expand Down
32 changes: 32 additions & 0 deletions src/CoreBundle/Migrations/Schema/V200/Version20250129120000.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

declare(strict_types=1);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a single space around assignment operators


/* For licensing terms, see /license.txt */

namespace Chamilo\CoreBundle\Migrations\Schema\V200;

use Chamilo\CoreBundle\Migrations\AbstractMigrationChamilo;
use Doctrine\DBAL\Schema\Schema;

final class Version20250129120000 extends AbstractMigrationChamilo

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing class doc comment

{
public function getDescription(): string
{
return 'Remove registration_date from user table and migrate data to created_at';
}

public function up(Schema $schema): void
{
$this->addSql('UPDATE user SET created_at = registration_date WHERE created_at IS NULL');

$this->addSql('ALTER TABLE user DROP COLUMN registration_date');
}

public function down(Schema $schema): void
{
$this->addSql('ALTER TABLE user ADD registration_date DATETIME DEFAULT NULL');

$this->addSql('UPDATE user SET registration_date = created_at WHERE registration_date IS NULL');
}
}
1 change: 0 additions & 1 deletion tests/CoreBundle/Repository/Node/UserRepositoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,6 @@ public function testCreateUserSkipResourceNode(): void
->setFirstname('Joe')
->setUsername('admin2')
->setSalt('')
->setRegistrationDate(new DateTime())
->setExpirationDate(new DateTime())
->setOpenid('')
->setSlug('admin2')
Expand Down
Loading