I’m doing some customization inside the CakeDC/users plug-in. I created a table with name “user_logs” which consist of foreign key relationship with the actual “users” table provided by CakeDC/users.
I baked the “user_logs” model using command:
bin\cake bake model UserLogs --plugin CakeDC/Users
After user gets login I’m just generating log transaction inside the “user_logs” table. I added the following line inside the “/vendor/cakedc/users/src/Controller/Traits/LoginTrait.php” file under _afterIdentifyUser
function:
$this->activity_log(‘Login’, ‘Login’, $user[‘id’]);
And activity_log
function is added inside the src/Controller/AppController.php file:
function activity_log($page, $action, $id=null){
$this->loadModel(‘CakeDC/Users.Userlogs’);
$dataUserLog = $this->Userlogs->newEntity();$dataUserLog['user_id'] = $this->request->session()->read('Auth.User.id'); if(!empty($id)){ $dataUserLog['reference_id'] = $id; } else { $dataUserLog['reference_id'] = 0; } $dataUserLog['activity_timestamp'] = date('Y-m-d H:i:s'); $dataUserLog['page'] = $page; $dataUserLog['action'] = $action; $this->Userlogs->save($dataUserLog); }
vendor/cakedc/users/src/Model/Entity/UserLog.php file code:
namespace CakeDC\Users\Model\Entity;
use Cake\ORM\Entity;
class UserLog extends Entity
{
protected $_accessible = [
‘user_id’ => true,
‘reference_id’ => true,
‘activity_timestamp’ => true,
‘page’ => true,
‘action’ => true,
‘user’ => true
];
}
vendor/cakedc/users/src/Model/Table/UserLogsTable.php file code:
namespace CakeDC\Users\Model\Table;
use Cake\ORM\Query;
use Cake\ORM\RulesChecker;
use Cake\ORM\Table;
use Cake\Validation\Validator;class UserLogsTable extends Table
{public function initialize(array $config) { parent::initialize($config); $this->setTable('user_logs'); $this->setDisplayField('id'); $this->setPrimaryKey('id'); $this->belongsTo('Users', [ 'foreignKey' => 'user_id', 'className' => 'CakeDC/Users.Users' ]); } public function validationDefault(Validator $validator) { $validator ->integer('id') ->allowEmptyString('id', null, 'create'); $validator ->dateTime('activity_timestamp') ->allowEmptyDateTime('activity_timestamp'); $validator ->scalar('page') ->maxLength('page', 255) ->allowEmptyString('page'); $validator ->scalar('action') ->maxLength('action', 255) ->allowEmptyString('action'); return $validator; } public function buildRules(RulesChecker $rules) { $rules->add($rules->existsIn(['user_id'], 'Users')); return $rules; }
}
The surprise part is! this works on localhost but when I’m uploading code on a server it’s not working. On localhost I’ve PHP v7.3.4 and on server I’ve PHP v5.6.40. Can any one suggest what’s wrong with this why it’s working on localhost and not on server? Everything is same I’ve done almost everything cleared model cache on server as well but no luck. Please help.
Not really sure why CAKEPHP is looking for table “proposal_db.userlogs” on server whereas I created “user_logs” table on both local and server. Please suggest?