Skip to content

Commit 81f872e

Browse files
authored
Merge pull request FriendsOfSymfony#2315 from stof/remove_fields
[BC Break] Remove more fields from the User class
2 parents 2ae86c3 + 7ad2a4b commit 81f872e

File tree

6 files changed

+27
-105
lines changed

6 files changed

+27
-105
lines changed

Model/User.php

Lines changed: 9 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -95,34 +95,18 @@ abstract class User implements UserInterface, GroupableInterface
9595
*/
9696
protected $groups;
9797

98-
/**
99-
* @var bool
100-
*/
101-
protected $locked;
102-
103-
/**
104-
* @var \DateTime
105-
*/
106-
protected $expiresAt;
107-
10898
/**
10999
* @var array
110100
*/
111101
protected $roles;
112102

113-
/**
114-
* @var \DateTime
115-
*/
116-
protected $credentialsExpireAt;
117-
118103
/**
119104
* User constructor.
120105
*/
121106
public function __construct()
122107
{
123108
$this->salt = base_convert(sha1(uniqid(mt_rand(), true)), 16, 36);
124109
$this->enabled = false;
125-
$this->locked = false;
126110
$this->roles = array();
127111
}
128112

@@ -153,11 +137,8 @@ public function serialize()
153137
$this->salt,
154138
$this->usernameCanonical,
155139
$this->username,
156-
$this->locked,
157140
$this->enabled,
158141
$this->id,
159-
$this->expiresAt,
160-
$this->credentialsExpireAt,
161142
$this->email,
162143
$this->emailCanonical,
163144
));
@@ -170,24 +151,23 @@ public function unserialize($serialized)
170151
{
171152
$data = unserialize($serialized);
172153

173-
if (9 === count($data)) {
174-
unset($data[4], $data[6]);
175-
176-
// add a few extra elements in the array to ensure that we have enough keys when unserializing
177-
// older data which does not include all properties.
178-
$data = array_merge($data, array_fill(0, 4, null));
154+
if (13 === count($data)) {
155+
// Unserializing a User object from 1.3.x
156+
unset($data[4], $data[5], $data[6], $data[9], $data[10]);
157+
$data = array_values($data);
158+
} elseif (11 === count($data)) {
159+
// Unserializing a User from a dev version somewhere between 2.0-alpha3 and 2.0-alpha4
160+
unset($data[4], $data[7], $data[8]);
161+
$data = array_values($data);
179162
}
180163

181164
list(
182165
$this->password,
183166
$this->salt,
184167
$this->usernameCanonical,
185168
$this->username,
186-
$this->locked,
187169
$this->enabled,
188170
$this->id,
189-
$this->expiresAt,
190-
$this->credentialsExpireAt,
191171
$this->email,
192172
$this->emailCanonical
193173
) = $data;
@@ -313,10 +293,6 @@ public function hasRole($role)
313293
*/
314294
public function isAccountNonExpired()
315295
{
316-
if (null !== $this->expiresAt && $this->expiresAt->getTimestamp() < time()) {
317-
return false;
318-
}
319-
320296
return true;
321297
}
322298

@@ -325,18 +301,14 @@ public function isAccountNonExpired()
325301
*/
326302
public function isAccountNonLocked()
327303
{
328-
return !$this->locked;
304+
return true;
329305
}
330306

331307
/**
332308
* {@inheritdoc}
333309
*/
334310
public function isCredentialsNonExpired()
335311
{
336-
if (null !== $this->credentialsExpireAt && $this->credentialsExpireAt->getTimestamp() < time()) {
337-
return false;
338-
}
339-
340312
return true;
341313
}
342314

@@ -345,11 +317,6 @@ public function isEnabled()
345317
return $this->enabled;
346318
}
347319

348-
public function isLocked()
349-
{
350-
return !$this->isAccountNonLocked();
351-
}
352-
353320
/**
354321
* {@inheritdoc}
355322
*/
@@ -391,18 +358,6 @@ public function setUsernameCanonical($usernameCanonical)
391358
return $this;
392359
}
393360

394-
/**
395-
* @param \DateTime $date
396-
*
397-
* @return User
398-
*/
399-
public function setCredentialsExpireAt(\DateTime $date = null)
400-
{
401-
$this->credentialsExpireAt = $date;
402-
403-
return $this;
404-
}
405-
406361
public function setEmail($email)
407362
{
408363
$this->email = $email;
@@ -430,18 +385,6 @@ public function setEnabled($boolean)
430385
return $this;
431386
}
432387

433-
/**
434-
* @param \DateTime $date
435-
*
436-
* @return User
437-
*/
438-
public function setExpiresAt(\DateTime $date = null)
439-
{
440-
$this->expiresAt = $date;
441-
442-
return $this;
443-
}
444-
445388
/**
446389
* {@inheritdoc}
447390
*/
@@ -486,16 +429,6 @@ public function setLastLogin(\DateTime $time = null)
486429
return $this;
487430
}
488431

489-
/**
490-
* {@inheritdoc}
491-
*/
492-
public function setLocked($boolean)
493-
{
494-
$this->locked = $boolean;
495-
496-
return $this;
497-
}
498-
499432
/**
500433
* {@inheritdoc}
501434
*/

Model/UserInterface.php

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -126,15 +126,6 @@ public function isSuperAdmin();
126126
*/
127127
public function setEnabled($boolean);
128128

129-
/**
130-
* Sets the locking status of the user.
131-
*
132-
* @param bool $boolean
133-
*
134-
* @return self
135-
*/
136-
public function setLocked($boolean);
137-
138129
/**
139130
* Sets the super admin status.
140131
*

Resources/config/doctrine-mapping/User.couchdb.xml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@
1111
<field name="salt" fieldName="salt" type="string" />
1212
<field name="password" fieldName="password" type="string" />
1313
<field name="lastLogin" fieldName="lastLogin" type="datetime" />
14-
<field name="locked" fieldName="locked" type="mixed" />
15-
<field name="expiresAt" fieldName="expiresAt" type="datetime" />
1614
<field name="confirmationToken" fieldName="confirmationToken" type="string" />
1715
<field name="passwordRequestedAt" fieldName="passwordRequestedAt" type="datetime" />
1816
<field name="roles" fieldName="roles" type="mixed" />

Resources/config/doctrine-mapping/User.mongodb.xml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,12 @@
2222

2323
<field name="lastLogin" fieldName="lastLogin" type="date" />
2424

25-
<field name="locked" fieldName="locked" type="boolean" />
26-
27-
<field name="expiresAt" fieldName="expiresAt" type="date" />
28-
2925
<field name="confirmationToken" fieldName="confirmationToken" type="string" />
3026

3127
<field name="passwordRequestedAt" fieldName="passwordRequestedAt" type="date" />
3228

3329
<field name="roles" fieldName="roles" type="collection" />
3430

35-
<field name="credentialsExpireAt" fieldName="credentialsExpireAt" type="date" />
3631
<indexes>
3732
<index>
3833
<key name="usernameCanonical" order="asc" />

Resources/config/doctrine-mapping/User.orm.xml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,12 @@
2222

2323
<field name="lastLogin" column="last_login" type="datetime" nullable="true" />
2424

25-
<field name="locked" column="locked" type="boolean" />
26-
27-
<field name="expiresAt" column="expires_at" type="datetime" nullable="true" />
28-
2925
<field name="confirmationToken" column="confirmation_token" type="string" length="180" unique="true" nullable="true" />
3026

3127
<field name="passwordRequestedAt" column="password_requested_at" type="datetime" nullable="true" />
3228

3329
<field name="roles" column="roles" type="array" />
3430

35-
<field name="credentialsExpireAt" column="credentials_expire_at" type="datetime" nullable="true" />
36-
3731
</mapped-superclass>
3832

3933
</doctrine-mapping>

Upgrade.md

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,24 @@ break. For the full list of changes, please look at the Changelog file.
88

99
Methods and properties removed from `FOS\UserBundle\Model\User`
1010

11-
- `$expired`
12-
- `$credentialsExpired`
13-
- `setExpired()` (use `setExpiresAt(\DateTime::now()` instead)
14-
- `setCredentialsExpired()` (use `setCredentialsExpireAt(\DateTime::now()` instead)
15-
16-
You need to drop the fields `expired` and `credentials_expired` from your database
17-
schema, because they aren't mapped anymore.
11+
- `$locked`
12+
- `$expired` and `$expiredAt`
13+
- `$credentialsExpired` and `$credentialsExpired`
14+
- `setLocked()` and `isLocked()`
15+
- `setExpired()` and `setExpiresAt()`
16+
- `setCredentialsExpired()` and `setCredentialsExpireAt()`
17+
18+
These properties were used to implement advanced features of the AdvancedUserInterface
19+
from the Symfony component, but neither Symfony nor this bundle are providing
20+
ways to use these features fully (expired credentials would just prevent
21+
logging in for instance).
22+
Projects needing to use these advanced feature should add the fields they
23+
need in their User class and override the corresponding method to provide
24+
an implementation fitting their requirement. Projects wanting to keep the
25+
previous behavior of the bundle can copy the condition used in 1.3.7.
26+
27+
You need to drop the removed fields from your database schema, because they
28+
aren't mapped anymore.
1829

1930
### LoginManager
2031

0 commit comments

Comments
 (0)