0

I am trying to add user with shell command I am getting this error

PHP Parse error:  syntax error, unexpected 'require_once' (T_REQUIRE_ONCE) in /var/www/magento/shell/create_user.php on line 4

This is the file in shell folder

                                 shell/create_user.php                                               
<?php

// Create New admin User programmatically.
require_once('app/Mage.php');
umask(0);
Mage::app();

try {
    $user = Mage::getModel('admin/user')
        ->setData(array(
            'username'  => 'username',
            'firstname' => 'firstname',
            'lastname'  => 'lastname',
            'email'     => '[email protected]',
            'password'  => 'password!!',
            'is_active' => 1
        ))->save();

} catch (Exception $e) {
    echo $e->getMessage();
    exit;
}

//Assign Role Id
try {
    $user->setRoleIds(array(1)) //Administrator role id is 1 ,Here you can assign other roles ids
        ->setRoleUserId($user->getUserId())
        ->saveRelations();

} catch (Exception $e) {
    echo $e->getMessage();
    exit;
}

echo "User created successfully";

1 Answer 1

1

Well it is a question of formatting , It is working now

Just for information I use PHPStorm this is the code

<?php

require_once('app/Mage.php');
umask(0);
Mage::app();

try {
    $user = Mage::getModel('admin/user')
        ->setData(array(
            'username' => 'username',
            'firstname' => 'firstname',
            'lastname' => 'lastname',
            'email' => '[email protected]',
            'password' => 'password123',
            'is_active' => 1
        ))->save();

} catch (Exception $e) {
    echo $e->getMessage();
    exit;
}

try {
    $user->setRoleIds(array(1))
        ->setRoleUserId($user->getUserId())
        ->saveRelations();

} catch (Exception $e) {
    echo $e->getMessage();
    exit;
}

echo "User created successfully";

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.