@@ -45,6 +45,48 @@ public function execute(LoggerInterface $logger)
45
45
*/
46
46
protected function doExecute (LoggerInterface $ logger , $ dryRun = false )
47
47
{
48
+ $ query = 'SELECT id, name, user_owner_id, organization_id, name, createdAt, updatedAt ' .
49
+ 'FROM orocrm_sales_b2bcustomer WHERE account_id IS NULL ' ;
50
+ $ customersWithoutAccount = $ this ->connection ->fetchAll ($ query );
51
+ foreach ($ customersWithoutAccount as $ customer ) {
52
+ $ query = 'INSERT INTO orocrm_account SET user_owner_id = :user_owner_id, ' .
53
+ 'organization_id = :organization_id, name = :name, createdAt = :createdAt, ' .
54
+ 'updatedAt = :updatedAt, serialized_data = :serialized_data ' ;
55
+ $ this ->connection ->executeQuery (
56
+ $ query ,
57
+ [
58
+ 'user_owner_id ' => $ customer ['user_owner_id ' ],
59
+ 'organization_id ' => $ customer ['organization_id ' ],
60
+ 'name ' => $ customer ['name ' ],
61
+ 'createdAt ' => $ customer ['createdAt ' ],
62
+ 'updatedAt ' => $ customer ['updatedAt ' ],
63
+ 'serialized_data ' => base64_encode (serialize (null )),
64
+ ],
65
+ [
66
+ 'user_owner_id ' => 'integer ' ,
67
+ 'organization_id ' => 'integer ' ,
68
+ 'name ' => 'string ' ,
69
+ 'createdAt ' => 'integer ' ,
70
+ 'updatedAt ' => 'integer ' ,
71
+ 'serialized_data ' => 'string ' ,
72
+ ]
73
+ );
74
+ $ accountId = $ this ->connection ->lastInsertId ();
75
+
76
+ $ query = 'UPDATE orocrm_sales_b2bcustomer SET account_id = :account_id WHERE id = :id ' ;
77
+ $ this ->connection ->executeQuery (
78
+ $ query ,
79
+ [
80
+ 'account_id ' => $ accountId ,
81
+ 'id ' => $ customer ['id ' ],
82
+ ],
83
+ [
84
+ 'account_id ' => 'integer ' ,
85
+ 'id ' => 'integer ' ,
86
+ ]
87
+ );
88
+ }
89
+
48
90
$ query = 'INSERT INTO orocrm_sales_customer (account_id, ' . $ this ->customerColumnName . ') '
49
91
. ' SELECT account_id, id FROM orocrm_sales_b2bcustomer ' ;
50
92
0 commit comments