Update for images in connections
authorSteve Sutton <steve@gaslightmedia.com>
Tue, 25 Sep 2018 17:47:04 +0000 (13:47 -0400)
committerSteve Sutton <steve@gaslightmedia.com>
Tue, 25 Sep 2018 17:47:04 +0000 (13:47 -0400)
Bring any missing images in to the member info

models/admin/management/development.php

index e100e73..ccbdf77 100644 (file)
@@ -13,6 +13,7 @@
  * @version  0.1
  */
 
+require_once GLM_MEMBERS_PLUGIN_PATH . '/models/admin/ajax/imageUpload.php';
 /**
  * This class performs the work for the default action of the "Members" menu
  * option, which is to display the members dashboard.
@@ -153,6 +154,7 @@ class GlmMembersAdmin_management_development
             break;
 
             case 'updateImages':
+                $ImageUpload = new GlmMembersAdmin_ajax_imageUpload( $this->wpdb, $this->config );
                 $sql = "
                 SELECT id,organization,options
                   FROM ".$this->wpdb->prefix."connections
@@ -165,42 +167,51 @@ class GlmMembersAdmin_management_development
                     // Need to get the member_info id based on the ref_dest
                     $options_data = unserialize( $member['options'] );
                     if ( $options_data['logo'] ) {
-                        // echo '<pre>$options_data: logo ' . print_r( $options_data['logo'], true ) . '</pre>';
+                        $logoPath = $options_data['logo']['meta']['path'];
                     } else if ( $options_data['image'] ) {
-                        // echo '<pre>$options_data: image ' . print_r( $options_data['image'], true ) . '</pre>';
+                        $logoPath = $options_data['image']['meta']['original']['path'];
+                    }
+                    if ( $logoPath ) {
+                        $memberLogo = $this->wpdb->get_var(
+                            $this->wpdb->prepare(
+                                "SELECT logo
+                                   FROM " . GLM_MEMBERS_PLUGIN_DB_PREFIX . "member_info
+                                  WHERE member = ( SELECT id
+                                                     FROM " . GLM_MEMBERS_PLUGIN_DB_PREFIX . "members
+                                                     WHERE old_member_id = %s
+                                                )",
+                                $member['id']
+                            )
+                        );
+                        if ( !$memberLogo ) {
+                            echo '<pre>image not found: ' . print_r( 'image not found', true ) . '</pre>';
+                            if ( is_file( $logoPath ) ) {
+                                $logo = $ImageUpload->storeImage($logoPath);
+                                if ($logo === false) {
+                                    $logo = '';
+                                } else {
+                                    $logo = $logo['newFileName'];
+                                }
+                            } else {
+                                $logo = '';
+                            }
+                            echo '<pre>$logo: ' . print_r( $logo, true ) . '</pre>';
+                            if ( $logo ) {
+                                $this->wpdb->query(
+                                    $this->wpdb->prepare(
+                                        "UPDATE " . GLM_MEMBERS_PLUGIN_DB_PREFIX . "member_info
+                                            SET logo = %s
+                                          WHERE member = ( SELECT id
+                                                             FROM " . GLM_MEMBERS_PLUGIN_DB_PREFIX . "members
+                                                            WHERE old_member_id = %d
+                                                            )",
+                                        $logo,
+                                        $member['id']
+                                    )
+                                );
+                            }
+                        }
                     }
-                    $memberInfoId = $this->wpdb->get_var(
-                        $this->wpdb->prepare(
-                            "SELECT logo
-                               FROM " . GLM_MEMBERS_PLUGIN_DB_PREFIX . "member_info
-                              WHERE member = ( SELECT id
-                                                 FROM " . GLM_MEMBERS_PLUGIN_DB_PREFIX . "members
-                                                 WHERE old_member_id = %s
-                                            )",
-                            $member['id']
-                        )
-                    );
-                    echo '<pre>$memberInfoId: ' . print_r( $memberInfoId, true ) . '</pre>';
-                    // $email = '';
-                    // if ( is_array( $options_data ) ) {
-                    //     reset( $options_data );
-                    //     $eData = current( $options_data );
-                    //     $email = $eData['address'];
-                    // }
-                    // if ( $email ) {
-                    //     $this->wpdb->query(
-                    //         $this->wpdb->prepare(
-                    //             "UPDATE " . GLM_MEMBERS_PLUGIN_DB_PREFIX . "member_info
-                    //                 SET email = %s
-                    //               WHERE member = ( SELECT id
-                    //                                  FROM " . GLM_MEMBERS_PLUGIN_DB_PREFIX . "members
-                    //                                 WHERE old_member_id = %d
-                    //                                 )",
-                    //             $email,
-                    //             $member['id']
-                    //         )
-                    //     );
-                    // }
                 }
                 break;