From d6d714b44e6c9ffca90759ce1a5f4629fdc84b6e Mon Sep 17 00:00:00 2001 From: Steve Sutton Date: Tue, 25 Apr 2017 11:59:45 -0400 Subject: [PATCH] Adding abstract file type to special case for copy of file for clone When cloning the entry it needs to check for file types also. Coping the logic for the images and use for file type. With the exception of the folders for sizes which is not needed for files. --- lib/GlmDataAbstract/DataAbstract.php | 41 +++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/lib/GlmDataAbstract/DataAbstract.php b/lib/GlmDataAbstract/DataAbstract.php index 4845a3fc..22afc4e2 100644 --- a/lib/GlmDataAbstract/DataAbstract.php +++ b/lib/GlmDataAbstract/DataAbstract.php @@ -3461,6 +3461,7 @@ $forEdit = true; // Build field list string including all but the ID field $fields = ''; $imageFields = array(); + $fileFields = array(); $sep = ''; foreach ($this->fieldData as $f) { @@ -3471,9 +3472,14 @@ $forEdit = true; } // Located any fields that require special processing + // Images if ($f['type'] == 'image') { $imageFields[] = $f['name']; } + // Files + if ( $f['type'] == 'file' ) { + $fileFields[] = $f['name']; + } } // Assemble query to duplicate the record. @@ -3539,6 +3545,39 @@ $forEdit = true; } + if ( count( $fileFields ) > 0 ) { + $updateSQL = ''; + $sep = ''; + foreach ( $fileFields as $f ) { + // If there's an file referenced + if ( $newData[$f] != '' ) { + // Create new file name + $newName = preg_replace('/\d{10}/', time(), $newData[$f]); + // Check if we have the original file, then copy it to the new name + if ( file_exists( GLM_MEMBERS_PLUGIN_FILES_PATH . '/' . $newData[$f] ) ) { + copy( + GLM_MEMBERS_PLUGIN_FILES_PATH . '/' . $newData[$f], + GLM_MEMBERS_PLUGIN_FILES_PATH . '/' . $newName + ); + } + // Add to sql to update this field + $updateSQL .= $sep."$f = '$newName'"; + $sep = ', '; + } + } + + // If there were any updates + if ($updateSQL != '') { + + $sql = " + UPDATE ".$this->table." + SET $updateSQL + WHERE id = $newID + ;"; + $this->wpdb->query( $sql ); + } + } + return $newID; } @@ -4245,4 +4284,4 @@ $forEdit = true; } -?> \ No newline at end of file +?> -- 2.17.1