310afb59 by Jeremy Groot

added broker id

1 parent fdd55866
...@@ -7,6 +7,50 @@ if ( class_exists( 'WP_CLI' ) ) { ...@@ -7,6 +7,50 @@ if ( class_exists( 'WP_CLI' ) ) {
7 campaign_Monitor_LoadData(); 7 campaign_Monitor_LoadData();
8 } 8 }
9 9
10 public function shift_brokers_from_to($args) {
11
12 $from = $args[0];
13 $to = $args[1];
14
15 $broker_list = getBrokerageList();
16
17 foreach($broker_list as $broker) {
18 if($broker['broker_id'] == $from) {
19 $from_brokerage = $broker;
20 }
21 if($broker['broker_id'] == $to) {
22 $to_brokerage = $broker;
23 }
24 }
25
26 if(!$from_brokerage) {
27 WP_CLI::log('From Brokerage not found!');
28 return;
29 }
30
31 if(!$to_brokerage) {
32 WP_CLI::log('To Brokerage not found!');
33 return;
34 }
35
36 $all_brokers = get_users();
37
38 foreach($all_brokers as $broker) {
39
40 $old_broker_id = get_user_meta($broker->ID, 'broker_id', true);
41
42 if($old_broker_id == $from_brokerage['broker_id']) {
43
44 update_user_meta($broker->ID, 'broker_id', $to_brokerage['broker_id']);
45
46 }
47
48 }
49
50
51
52 }
53
10 function import_brokers_from_csv() { 54 function import_brokers_from_csv() {
11 $data = []; 55 $data = [];
12 $row = 0; 56 $row = 0;
...@@ -300,6 +344,7 @@ if ( class_exists( 'WP_CLI' ) ) { ...@@ -300,6 +344,7 @@ if ( class_exists( 'WP_CLI' ) ) {
300 $new_brokers = []; 344 $new_brokers = [];
301 345
302 $row = 0; 346 $row = 0;
347 $id = 1;
303 if (($handle = fopen(wp_get_upload_dir()['basedir'] . "/" . $args[0], "r")) !== FALSE) { 348 if (($handle = fopen(wp_get_upload_dir()['basedir'] . "/" . $args[0], "r")) !== FALSE) {
304 while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) { 349 while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
305 if($row == 0) { 350 if($row == 0) {
...@@ -308,8 +353,9 @@ if ( class_exists( 'WP_CLI' ) ) { ...@@ -308,8 +353,9 @@ if ( class_exists( 'WP_CLI' ) ) {
308 } 353 }
309 $new_id = $data[0]; 354 $new_id = $data[0];
310 $name = $data[1]; 355 $name = $data[1];
311 $new_brokers[] = ["broker_id"=>$new_id,"brokerage"=>$name]; 356 $new_brokers[] = ['id'=>$id,"broker_id"=>$new_id,"brokerage"=>$name];
312 // echo $name; 357 // echo $name;
358 ++$id;
313 ++$row; 359 ++$row;
314 } 360 }
315 fclose($handle); 361 fclose($handle);
...@@ -319,7 +365,7 @@ if ( class_exists( 'WP_CLI' ) ) { ...@@ -319,7 +365,7 @@ if ( class_exists( 'WP_CLI' ) ) {
319 365
320 $old_saved_brokers = get_option('old_broker_list'); 366 $old_saved_brokers = get_option('old_broker_list');
321 if(!$old_saved_brokers) { 367 if(!$old_saved_brokers) {
322 update_option('old_broker_list', serialize($old_brokers)); 368 update_option('old_broker_list_feb92024', serialize($old_brokers));
323 } 369 }
324 370
325 update_option('broker_list', serialize($new_brokers)); 371 update_option('broker_list', serialize($new_brokers));
......