Setting up the cloning for the member info files.
authorSteve Sutton <steve@gaslightmedia.com>
Wed, 12 Apr 2017 15:56:20 +0000 (11:56 -0400)
committerSteve Sutton <steve@gaslightmedia.com>
Wed, 12 Apr 2017 15:56:20 +0000 (11:56 -0400)
Need to clone the files with member info.

classes/data/dataFiles.php
classes/glmMemberInfoClone.php

index d38d03e..459bdc3 100644 (file)
@@ -418,73 +418,62 @@ class GlmDataFiles extends GlmDataAbstract
      * @return boolean True if successful
      *
      */
-    public function galleryImageDataClone($refTypeSrc, $refIDSrc, $refTypeDst, $refIDDst)
+    public function filesDataClone($refTypeSrc, $refIDSrc, $refTypeDst, $refIDDst)
     {
 
         // Get Source Image Gallery
-        $imageGallerySrc = $this->getFiles($refTypeSrc, $refIDSrc);
+        $fileSrc = $this->getFiles($refTypeSrc, $refIDSrc);
 
         // Get the destination target table name
         $dstTable = $this->config['ref_type_table'][$refTypeDst];
 
-        // Get Image sizes and add original
-        $sizes = $this->config['imageSizes'];
-        $sizes['original'] = array();
-
         // If we have an image gallery with any files
-        if ($imageGallerySrc !== false
-            && is_array($imageGallerySrc)
-            && count($imageGallerySrc) > 0) {
+        if ($fileSrc !== false
+            && is_array($fileSrc)
+            && count($fileSrc) > 0) {
 
             // for each gallery image
-            foreach ($imageGallerySrc as $i) {
-
-            $srcName = $i['file_name'];
+            foreach ($fileSrc as $i) {
 
-            // Strip the source table name and ID from the file name (part after first '-')
-            $dstName = $dstTable.'_'.$refIDDst.'-'.substr(strchr($i['file_name'], '-'), 1);
+                $srcName = $i['file_name'];
 
-            // For each image size
-            reset($sizes);
-            while (list($k, $v) = each($sizes)) {
+                // Strip the source table name and ID from the file name (part after first '-')
+                $dstName = $dstTable.'_'.$refIDDst.'-'.substr(strchr($i['file_name'], '-'), 1);
 
-            // Check if the source image exists
-            if (is_file(GLM_MEMBERS_PLUGIN_FILES_PATH.'/'.$k.'/'.$srcName)) {
+                // Check if the source image exists
+                if (is_file(GLM_MEMBERS_PLUGIN_FILES_PATH.'/'.$srcName)) {
 
-                // Copy src file to dst file for this size
-                copy(GLM_MEMBERS_PLUGIN_FILES_PATH.'/'.$k.'/'.$srcName, GLM_MEMBERS_PLUGIN_FILES_PATH.'/'.$k.'/'.$dstName);
+                    // Copy src file to dst file for this size
+                    copy(GLM_MEMBERS_PLUGIN_FILES_PATH.'/'.$srcName, GLM_MEMBERS_PLUGIN_FILES_PATH.'/'.$dstName);
 
-            }
-            }
+                }
 
-            // Add this image to the files table
-            // Store image name in files table
-            $sql = "
-            INSERT INTO ".GLM_MEMBERS_PLUGIN_DB_PREFIX ."files
-                (
-                    name,
-                    file_name,
-                    descr,
-                    caption,
-                    status,
-                    position,
-                    ref_type,
-                    ref_dest
-                )
-            VALUES
-                (
-                    '".$i['name']."',
-                    '$dstName',
-                    '".addslashes($i['descr'])."',
-                    '".addslashes($i['caption'])."',
-                    ".$i['status']['value'].",
-                    ".$i['position'].",
-                    $refTypeDst,
-                    $refIDDst
-                );
-            ";
-            $this->wpdb->query($sql);
-            // $queryError = $this->wpdb->last_error;
+                // Add this image to the files table
+                // Store image name in files table
+                $sql = "
+                INSERT INTO ".GLM_MEMBERS_PLUGIN_DB_PREFIX ."files
+                    (
+                        name,
+                        file_name,
+                        caption,
+                        status,
+                        position,
+                        ref_type,
+                        ref_dest
+                    )
+                VALUES
+                    (
+                        '".$i['name']."',
+                        '$dstName',
+                        '".addslashes($i['caption'])."',
+                        ".$i['status']['value'].",
+                        ".$i['position'].",
+                        $refTypeDst,
+                        $refIDDst
+                    );
+                ";
+                $this->wpdb->query($sql);
+                // $queryError = $this->wpdb->last_error;
 
             }
 
index 32d223d..c09cd1a 100644 (file)
@@ -118,6 +118,12 @@ class GlmMemberInfoClone
             // Clone the image gallery
             $Images->galleryImageDataClone($refType, $id, $refType, $newID);
 
+            // Load file class
+            require_once GLM_MEMBERS_PLUGIN_CLASS_PATH.'/data/dataFiles.php';
+            $Files = new GlmDataFiles($this->wpdb, $this->config);
+
+            // Clone the files
+            $Files->filesDataClone($refType, $id, $refType, $newID);
 
         }
 
@@ -127,4 +133,4 @@ class GlmMemberInfoClone
 
 }
 
-?>
\ No newline at end of file
+?>