jeudi 20 juin 2019

Mysql procedure not doing anything and no error

My main objective is to apply if else in sql query so i can check if there is an admin user update the password for the admin user and if there is no admin user create that admin user via script. the above piece if code is for magento 1.9

I need to perform this operation via mysql

delimiter //

create procedure admin_user() 

begin

set @isAdmin := (select count(*) from admin_user where username = 'admin');

-- Only insert rows if the platform was found
if @isAdmin is not null then 

    UPDATE admin_user SET password = '49ecf011a4046493514c9d43bbfdd6e6:Sm4AZH3YkKQP9NEG0XRaUJfFiJxfYPeN' WHERE username = 'admin';

else

    set @salt := 'ls';
    set @pass := CONCAT(MD5(CONCAT( @salt , "admin123") ), CONCAT(":", @salt ));

    INSERT INTO `admin_user` (firstname, lastname, email, username, password, created, lognum, reload_acl_flag, is_active, extra, rp_token, rp_token_created_at)
    VALUES ('admin', 'dev', 'admin@bamba.local', 'admin', @pass, NOW(), 0, 0, 1, 'N;',null,null);

    INSERT INTO `admin_role` (parent_id, tree_level, sort_order, role_type, user_id, role_name) 
    VALUES (0, 1, 0 , 'G', 0, 'Development');

    set @role_id := (SELECT role_id from admin_role where role_name='Development');

    INSERT INTO `admin_rule` (role_id, resource_id, privileges, assert_id, role_type, permission)
    VALUES (@role_id, 'all', null, 0, 'G', 'allow');

    INSERT INTO `admin_role` (parent_id, tree_level, sort_order, role_type, user_id, role_name)
    VALUES (@role_id, 2, 0, 'U', (SELECT user_id FROM admin_user WHERE username = 'admin'), 'admin');

end if;

   end;

//

delimiter ;

-- Execute the procedure
call admin_user();

-- Drop the procedure
drop procedure admin_user;

When query works in term of execution, its say query executed 0 row affected. Don't get any results

Aucun commentaire:

Enregistrer un commentaire