diff --git a/data/schema.ibmdb2.sql b/data/schema.ibmdb2.sql index e6ca77b3..2b33fac6 100644 --- a/data/schema.ibmdb2.sql +++ b/data/schema.ibmdb2.sql @@ -1,6 +1,6 @@ CREATE TABLE user ( - user_id INTEGER PRIMARY KEY NOT NULL GENERATED ALWAYS AS IDENTITY (START WITH 1 INCREMENT BY 1), + id INTEGER PRIMARY KEY NOT NULL GENERATED ALWAYS AS IDENTITY (START WITH 1 INCREMENT BY 1), username VARCHAR(255) DEFAULT NULL UNIQUE, email VARCHAR(255) DEFAULT NULL UNIQUE, display_name VARCHAR(50) DEFAULT NULL, diff --git a/data/schema.mysql.sql b/data/schema.mysql.sql index 225ab6ee..353db239 100644 --- a/data/schema.mysql.sql +++ b/data/schema.mysql.sql @@ -1,6 +1,6 @@ CREATE TABLE `user` ( - `user_id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, + `id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, `username` VARCHAR(255) DEFAULT NULL UNIQUE, `email` VARCHAR(255) DEFAULT NULL UNIQUE, `display_name` VARCHAR(50) DEFAULT NULL, diff --git a/data/schema.pgsql.sql b/data/schema.pgsql.sql index 8fd397a9..86a67497 100644 --- a/data/schema.pgsql.sql +++ b/data/schema.pgsql.sql @@ -1,13 +1,13 @@ CREATE TABLE public.user ( - user_id serial NOT NULL, + id serial NOT NULL, username character varying(255) DEFAULT NULL UNIQUE, email character varying(255) DEFAULT NULL UNIQUE, display_name character varying(50) DEFAULT NULL, password character varying(128) NOT NULL, state smallint, -CONSTRAINT user_pkey PRIMARY KEY (user_id), +CONSTRAINT user_pkey PRIMARY KEY (id), CONSTRAINT user_username_key UNIQUE (username), CONSTRAINT user_email_key UNIQUE (email) ); diff --git a/data/schema.sql b/data/schema.sql index 2780cb6f..d973813a 100644 --- a/data/schema.sql +++ b/data/schema.sql @@ -1,6 +1,6 @@ CREATE TABLE user ( - user_id INTEGER PRIMARY KEY AUTO_INCREMENT NOT NULL, + id INTEGER PRIMARY KEY AUTO_INCREMENT NOT NULL, username VARCHAR(255) DEFAULT NULL UNIQUE, email VARCHAR(255) DEFAULT NULL UNIQUE, display_name VARCHAR(50) DEFAULT NULL, diff --git a/data/schema.sqlite.sql b/data/schema.sqlite.sql index 5aad8f11..9fe43ec5 100644 --- a/data/schema.sqlite.sql +++ b/data/schema.sqlite.sql @@ -1,6 +1,6 @@ CREATE TABLE user ( - user_id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, + id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, username VARCHAR(255) DEFAULT NULL UNIQUE, email VARCHAR(255) DEFAULT NULL UNIQUE, display_name VARCHAR(50) DEFAULT NULL, diff --git a/docs/check-user-logged-in.md b/docs/check-user-logged-in.md index 7d274928..c8f850b8 100644 --- a/docs/check-user-logged-in.md +++ b/docs/check-user-logged-in.md @@ -33,7 +33,7 @@ ZfcUser provides a Controller Plugin ([zfcUserAuthentication](https://github.com if ($this->zfcUserAuthentication()->hasIdentity()) { //get the email of the user echo $this->zfcUserAuthentication()->getIdentity()->getEmail(); - //get the user_id of the user + //get the id of the user echo $this->zfcUserAuthentication()->getIdentity()->getId(); //get the username of the user echo $this->zfcUserAuthentication()->getIdentity()->getUsername(); diff --git a/docs/custom-action-when-user-register.md b/docs/custom-action-when-user-register.md index 28475ff0..7ba96920 100644 --- a/docs/custom-action-when-user-register.md +++ b/docs/custom-action-when-user-register.md @@ -29,7 +29,7 @@ $em->attach('ZfcUser\Service\User', 'register', function($e) { ``` ## Retrieving the User Id -If you need to retrieve the `user_id`, just attach to `register.post` and the user entity should have it. +If you need to retrieve the `id`, just attach to `register.post` and the user entity should have it. ## Example diff --git a/src/ZfcUser/Form/Base.php b/src/ZfcUser/Form/Base.php index 1060923f..159d24a2 100644 --- a/src/ZfcUser/Form/Base.php +++ b/src/ZfcUser/Form/Base.php @@ -75,7 +75,7 @@ public function __construct() )); $this->add(array( - 'name' => 'userId', + 'name' => 'id', 'type' => 'Zend\Form\Element\Hidden', 'attributes' => array( 'type' => 'hidden' diff --git a/src/ZfcUser/Form/Register.php b/src/ZfcUser/Form/Register.php index e8c2197e..d28875c7 100644 --- a/src/ZfcUser/Form/Register.php +++ b/src/ZfcUser/Form/Register.php @@ -20,7 +20,7 @@ public function __construct($name, RegistrationOptionsInterface $options) $this->setRegistrationOptions($options); parent::__construct($name); - $this->remove('userId'); + $this->remove('id'); if (!$this->getRegistrationOptions()->getEnableUsername()) { $this->remove('username'); } diff --git a/src/ZfcUser/Mapper/User.php b/src/ZfcUser/Mapper/User.php index 08c10dec..1ba21355 100644 --- a/src/ZfcUser/Mapper/User.php +++ b/src/ZfcUser/Mapper/User.php @@ -32,7 +32,7 @@ public function findByUsername($username) public function findById($id) { $select = $this->getSelect() - ->where(array('user_id' => $id)); + ->where(array('id' => $id)); $entity = $this->select($select)->current(); $this->getEventManager()->trigger('find', $this, array('entity' => $entity)); @@ -53,14 +53,14 @@ public function insert($entity, $tableName = null, Hydrator $hydrator = null) { $hydrator = $hydrator ?: $this->getHydrator(); $result = parent::insert($entity, $tableName, $hydrator); - $hydrator->hydrate(array('user_id' => $result->getGeneratedValue()), $entity); + $entity->setId($result->getGeneratedValue()); return $result; } public function update($entity, $where = null, $tableName = null, Hydrator $hydrator = null) { if (!$where) { - $where = array('user_id' => $entity->getId()); + $where = array('id' => $entity->getId()); } return parent::update($entity, $where, $tableName, $hydrator); diff --git a/src/ZfcUser/Mapper/UserHydrator.php b/src/ZfcUser/Mapper/UserHydrator.php index 9323b3dc..14df34c2 100644 --- a/src/ZfcUser/Mapper/UserHydrator.php +++ b/src/ZfcUser/Mapper/UserHydrator.php @@ -36,7 +36,10 @@ public function extract($object) { $this->guardUserObject($object); $data = parent::extract($object); - return $this->mapField('id', 'user_id', $data); + if ($data['id'] === null) { + unset($data['id']); + } + return $data; } /** @@ -50,7 +53,6 @@ public function extract($object) public function hydrate(array $data, $object) { $this->guardUserObject($object); - $data = $this->mapField('user_id', 'id', $data); return parent::hydrate($data, $object); } diff --git a/tests/ZfcUserTest/Form/BaseTest.php b/tests/ZfcUserTest/Form/BaseTest.php index 4bc76b0a..367c4111 100644 --- a/tests/ZfcUserTest/Form/BaseTest.php +++ b/tests/ZfcUserTest/Form/BaseTest.php @@ -20,6 +20,6 @@ public function testConstruct() $this->assertArrayHasKey('password', $elements); $this->assertArrayHasKey('passwordVerify', $elements); $this->assertArrayHasKey('submit', $elements); - $this->assertArrayHasKey('userId', $elements); + $this->assertArrayHasKey('id', $elements); } } diff --git a/tests/ZfcUserTest/Form/RegisterTest.php b/tests/ZfcUserTest/Form/RegisterTest.php index 0fefbb22..971dde4b 100644 --- a/tests/ZfcUserTest/Form/RegisterTest.php +++ b/tests/ZfcUserTest/Form/RegisterTest.php @@ -22,7 +22,7 @@ public function testConstruct() $elements = $form->getElements(); - $this->assertArrayNotHasKey('userId', $elements); + $this->assertArrayNotHasKey('id', $elements); $this->assertArrayNotHasKey('username', $elements); $this->assertArrayNotHasKey('display_name', $elements); $this->assertArrayHasKey('email', $elements); @@ -58,7 +58,7 @@ public function testSetGetRegistrationOptions() * @param mixed $value = null * @return \ReflectionProperty */ - public function helperMakePropertyAccessable ($objectOrClass, $property, $value = null) + public function helperMakePropertyAccessable($objectOrClass, $property, $value = null) { $reflectionProperty = new \ReflectionProperty($objectOrClass, $property); $reflectionProperty->setAccessible(true); diff --git a/tests/ZfcUserTest/Mapper/UserHydratorTest.php b/tests/ZfcUserTest/Mapper/UserHydratorTest.php index 2b0b7af3..44cc96ff 100644 --- a/tests/ZfcUserTest/Mapper/UserHydratorTest.php +++ b/tests/ZfcUserTest/Mapper/UserHydratorTest.php @@ -74,7 +74,7 @@ public function testHydrateWithValidUserObject() 'display_name' => 'ZfcUser', 'password' => 'c4zyP455w0rd!', 'state' => '1', - 'user_id' => 1 + 'id' => 1 ); $result = $this->hydrator->hydrate($expectArray, $user); @@ -84,7 +84,7 @@ public function testHydrateWithValidUserObject() $this->assertEquals($expectArray['display_name'], $result->getDisplayName()); $this->assertEquals(static::ENCRYPTED_PASSWORD, $result->getPassword()); $this->assertEquals((int) $expectArray['state'], $result->getState()); - $this->assertEquals($expectArray['user_id'], $result->getId()); + $this->assertEquals($expectArray['id'], $result->getId()); } public function provideValidUserObjects() @@ -98,7 +98,7 @@ public function provideValidUserObjects() 'display_name' => 'ZfcUser', 'password' => 'ZfcUserPassword', 'state' => 1, - 'user_id' => 1 + 'id' => 1 ); $return[]=array($this->buildUser($buffer), $buffer); @@ -123,9 +123,6 @@ private function buildUser(array $data) { $user = new UserEntity; foreach ($data as $key => $value) { - if ($key == 'user_id') { - $key = 'id'; - } $method = 'set' . str_replace(" ", "", ucwords(str_replace("_", " ", $key))); call_user_func(array($user, $method), $value); } diff --git a/tests/ZfcUserTest/Mapper/UserTest.php b/tests/ZfcUserTest/Mapper/UserTest.php index 1fe001a2..a8be7847 100644 --- a/tests/ZfcUserTest/Mapper/UserTest.php +++ b/tests/ZfcUserTest/Mapper/UserTest.php @@ -356,7 +356,7 @@ public function providerTestFindBy() array($user->getId()), array( 'whereArgs'=>array( - array('user_id'=>$user->getId()), + array('id'=>$user->getId()), 'AND' ) ),