-
-
Save ibes/629919 to your computer and use it in GitHub Desktop.
| <?php | |
| /** | |
| * Vanilla Attachments to FileUpload Porter | |
| * This is not an official Vanilla Plugin, Layout was taken from Vanilla 2 Exporter | |
| * This script puts Vanilla1 Attachment files to Vanilla 2 FileUpload | |
| * see http://www.vanillaforums.org/discussion/13136/attachments-to-fileupload-importer for more information | |
| * The function of this script comes from user rayk. | |
| * brought to PHP and made more user friendly by user vegano | |
| */ | |
| $debug = true; // set to true to see the values of the fifth file that should be copied | |
| function pageHeader() { | |
| echo '<?xml version="1.0" encoding="UTF-8"?>'; | |
| ?> | |
| <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> | |
| <html> | |
| <head> | |
| <title>Vanilla Attachments to FileUpload Porter - Form Vanilla1 to Vanilla2</title> | |
| <!-- Contents included from style.css --> | |
| <style> | |
| body { | |
| font-family: 'lucida grande','Lucida Sans Unicode', tahoma, sans-serif; | |
| background: url('http://vanillaforums.com/porter/slicesplash.jpg') top center no-repeat #C7E6FB; | |
| margin: 0px; | |
| padding: 0px; | |
| text-align: center; | |
| color:#076C8E; | |
| text-shadow:0 1px 0 #FFFFFF; | |
| } | |
| a, | |
| a:link, | |
| a:active, | |
| a:visited { | |
| color: #2786C2; | |
| text-decoration: none; | |
| } | |
| a:hover { | |
| color: #FF0084 !important; | |
| text-decoration: underline; | |
| } | |
| div.Title { | |
| background:#E2F4FF none repeat scroll 0 0; | |
| border-top: 1px solid #A5D0E7; | |
| border-bottom: 1px solid #A5D0E7; | |
| margin: 50px 0; | |
| padding: 30px 0 4px; | |
| } | |
| div.Title h1 { | |
| text-align: left; | |
| width: 600px; | |
| margin: 0 auto; | |
| } | |
| div.Title img { | |
| top: 20px; | |
| position: absolute; | |
| } | |
| div.Title p { | |
| padding: 0 0 0 270px; | |
| margin: 0; | |
| font-size: 30px; | |
| } | |
| h1 { | |
| font-family: Arial, Helvetica, Verdana; | |
| color: #02455B; | |
| width: 568px; | |
| margin: 0 auto; | |
| padding: 0; | |
| font-size: 180%; | |
| } | |
| div.Form { | |
| text-align: center; | |
| } | |
| div.Form ul { | |
| width: 500px; | |
| margin: 0 auto; | |
| padding: 0; | |
| } | |
| div.Errors { | |
| background: #d00; | |
| padding: 20px 8px !important; | |
| margin: 0 0 10px; | |
| border-bottom: 1px solid #C0E7F5; | |
| } | |
| .Errors li { | |
| padding: 4px 0 !important; | |
| border: 0px !important; | |
| margin: 0px !important; | |
| color: #fff !important; | |
| font-size: 16px; | |
| line-height: 150%; | |
| text-shadow: #900 0 1px 0; | |
| } | |
| .Errors li pre, | |
| .Errors li code { | |
| border-radius: 3px; | |
| -moz-border-radius: 3px; | |
| -webkit-border-radius: 3px; | |
| border: 1px solid #b00; | |
| background: #c00; | |
| margin: 10px 0 0; | |
| padding: 4px 8px; | |
| display: block; | |
| text-shadow: none; | |
| font-size: 13px; | |
| font-weight: normal; | |
| font-family: monospace; | |
| } | |
| .Errors li a { | |
| color: #ffff00; | |
| text-decoration: underline; | |
| } | |
| .Errors li a:hover { | |
| color: #ff0 !important; | |
| text-decoration: none; | |
| } | |
| .Hidden { | |
| display: none; | |
| } | |
| /* Forms */ | |
| form { | |
| margin: 0 0 20px; | |
| text-align: right; | |
| } | |
| form ul { | |
| text-align: left; | |
| list-style: none; | |
| margin: 0px; | |
| padding: 10px; | |
| } | |
| form ul li { | |
| padding: 10px 0; | |
| font-size: 18px; | |
| } | |
| form ul li.Warning { | |
| padding-bottom: 0; | |
| border-bottom: 0; | |
| font-size: 17px; | |
| } | |
| form ul li.Warning div { | |
| font-size: 14px; | |
| line-height: 1.6; | |
| color: #000; | |
| text-shadow: none; | |
| padding: 16px 0 8px; | |
| } | |
| form label { | |
| font-family: Arial, Helvetica, Verdana; | |
| font-weight: bold; | |
| display: block; | |
| padding: 8px 0 0; | |
| font-size: 110%; | |
| color: #02455B; | |
| } | |
| form label span { | |
| font-size: 13px; | |
| color: #555; | |
| font-weight: normal; | |
| text-shadow: none; | |
| padding: 0 0 0 10px; | |
| } | |
| form select { | |
| border-radius: 4px; | |
| -moz-border-radius: 4px; | |
| -webkit-border-radius: 4px; | |
| font-size: 110%; | |
| padding: 8px; | |
| width: 496px; | |
| border: 1px solid #ccc; | |
| color: #555; | |
| } | |
| form input.InputBox { | |
| border-radius: 4px; | |
| -moz-border-radius: 4px; | |
| -webkit-border-radius: 4px; | |
| font-size: 110%; | |
| padding: 8px; | |
| width: 480px; | |
| border: 1px solid #ccc; | |
| color: #555; | |
| } | |
| form input.InputBox:focus { | |
| color: #000; | |
| background: #FFFEDE; | |
| border: 1px solid #aaa; | |
| } | |
| form li.Last { | |
| padding: 12px 0 2px; | |
| border-bottom: 0; | |
| } | |
| div.Button { | |
| text-align: right; | |
| padding: 12px 0 30px; | |
| width: 496px; | |
| margin: 0 auto; | |
| } | |
| div.Button a, | |
| input.Button { | |
| cursor: pointer; | |
| font-family: arial, helvetica, verdana; | |
| font-size: 25px; | |
| font-weight: bold; | |
| color: #02475A; | |
| text-shadow: 0 1px 0 #fff; | |
| margin: 0; | |
| padding: 3px 10px; | |
| background: url('http://vanillaforums.com/porter/buttonbg.png') repeat-x center left #f8f8f8; | |
| border: 1px solid #999; | |
| border-radius: 3px; | |
| -moz-border-radius: 3px; | |
| -webkit-border-radius: 3px; | |
| box-shadow: 0px 0px 2px #999; | |
| -moz-box-shadow: 0px 0px 2px #999; | |
| -webkit-box-shadow: 0px 0px 2px #999; | |
| } | |
| div.Button a { | |
| padding: 4px 8px; | |
| } | |
| div.Button a:hover, | |
| input.Button:hover { | |
| text-decoration: none; | |
| color: #111; | |
| border: 1px solid #666; | |
| } | |
| div.Button a:focus, | |
| input.Button:focus { | |
| background: #eee; | |
| } | |
| /* readme.html */ | |
| div.Info { | |
| text-align: left; | |
| width: 568px; | |
| margin: 0 auto 0px; | |
| font-size: 80%; | |
| line-height: 1.6; | |
| } | |
| div.Info h1 { | |
| padding: 6px 0 0; | |
| margin: 0; | |
| } | |
| div.Info p { | |
| color: #000; | |
| padding: 3px 0 6px; | |
| margin: 0; | |
| text-shadow: none; | |
| } | |
| div.Info li { | |
| color: #000; | |
| padding: 1px 0; | |
| margin: 0; | |
| text-shadow: none; | |
| } | |
| code { | |
| font-size: 120%; | |
| font-family: Greorgia, Courier New, serif; | |
| } | |
| div.Code { | |
| background-color: #fff; | |
| border-radius: 4px; | |
| -moz-border-radius: 4px; | |
| -webkit-border-radius: 4px; | |
| padding: 8px; | |
| border: 1px solid #ccc; | |
| color: #555; | |
| } | |
| div.Report { | |
| font-size:70%; | |
| text-align: left; | |
| padding-left: 50px; | |
| } | |
| .Version { | |
| font-size: 9pt; | |
| font-weight: normal; | |
| } | |
| </style> | |
| </head> | |
| <body> | |
| <h1>Let's get your files of Vanilla1 Attachments to Vanilla2 FileUpload.</h1> | |
| <div class="Info"> | |
| <h2>STEP1: Work on database</h2> | |
| First run this query to insert your old attachments table data into FileUpload table.<br /> | |
| <div class="Code"><code> | |
| INSERT INTO GDN_Media (Name, Type, Size, StorageMethod, Path, InsertUserID, ForeignID, ForeignTable) SELECT Name, MimeType, Size, 'local', Path, 1, CommentID, 'comment' from LUM_Attachment</code></div> | |
| <br /> | |
| After that you need to extract the necessary data from the GDN_Media table in CSV format.<br /> | |
| Run an SQL query: | |
| <div class="Code"><code>SELECT Path, MediaID FROM `GDN_Media`<code></div> | |
| When the result comes up, click the "Export" button at the bottom of the page and export as CSV<br /> | |
| Save the file onto your server</p> | |
| <p>You should have a list of paths to media ids, like this (I made a copy of my old attachments inside FileUpload):<br /> | |
| <div class="Code"><code> | |
| "FileUpload/2010/07/filename01.jpg";"3626"<br /> | |
| "FileUpload/2010/07/filename02.jpg";"3625" | |
| </code></div> | |
| </p> | |
| <h2>STEP2: Work with your files</h2> | |
| <p>You will have to fill in some paths to files</p> | |
| </div> | |
| <?php | |
| } | |
| function pageFooter() | |
| { | |
| ?> | |
| <h2>Thanks to</h2> | |
| <p>Many thanks for the first step goes to user <strong>rayk</strong> and his friend who is doing Ruby</p> | |
| <p>The second step - bring it to PHP and make a little bit of GUI - was done by user <strong>vegano</strong></p> | |
| </body> | |
| </html> | |
| <?php | |
| } | |
| // Form function | |
| function showForm ($errorCSV = false, $errorAttachments = false,$errorFileUpload = false){ | |
| if($errorCSV) $errorTextCSV = "Please enter a valid path to your CSV file!"; | |
| if($errorAttachments) $errorTextAttachments = "Please enter a valid path to your attachments folder!"; | |
| if($errorFileUpload) $errorTextFileUpload = "Please enter a valid path to your attachments folder!"; | |
| ?> | |
| <form action = "<?php $_SERVER['PHP_SELF']; ?>" method = "post"><table> | |
| <div class="Form"> | |
| <ul> | |
| <li> | |
| <label><input class="CheckBox" type="checkbox" name="test" value="test" /> Testrun <span>won't copy any files</span> | |
| </label> | |
| </li> | |
| <li> | |
| <label>Path to CSV file <span>see Step 1 for more Infos</span></label> | |
| <?php if($errorCSV) echo $errorTextCSV; ?> | |
| <input class="InputBox" type="text" name="csv"> | |
| </li> | |
| <li> | |
| <label>Path to Attachments folder <span>Vanilla 1</span></label$> | |
| <?php if($errorAttachments) echo $errorTextAttachments; ?> | |
| <input class="InputBox" type="text" name="attachments"> | |
| </li> | |
| <li> | |
| <label>Path to FileUpload folder<span>Vanilla 2</span></label> | |
| <?php if($errorFileUpload) echo $errorTextFileUpload; ?> | |
| <input class="InputBox" type="text" name="fileupload"> | |
| </li> | |
| <li> | |
| <label>Dispersion Factor<span>Default is 20, please specify Plugin.FileUpload.DispersionFactor if different from default.</span></label> | |
| <input class="InputBox" name="dispersion" type="text" value="" /> | |
| </li> | |
| </ul> | |
| <div class="Button"> | |
| <input class="Button" name="SubmitForm" type="submit" value="Begin Export" /> | |
| </div> | |
| </form> | |
| <?php | |
| } | |
| pageHeader (); | |
| if(!isset($_POST['SubmitForm'])) | |
| { | |
| showForm(); | |
| } | |
| else{ | |
| // Check inputs | |
| $errorCSV = false; | |
| $errorAttachments = false; | |
| $errorFileUpload = false; | |
| $testrun = ($_POST['test'] == true) ? true : false; | |
| $csv = isset($_POST['csv']) ? trim($_POST['csv']) : ''; | |
| $attachments = isset($_POST['attachments']) ? trim($_POST['attachments']) : ''; | |
| $fileupload = isset($_POST['fileupload']) ? trim($_POST['fileupload']) : ''; | |
| $dispersion = isset($_POST['dispersion']) ? trim($_POST['dispersion']) : 20; | |
| if ( !isset($csv) || !file_exists($csv) ) $errorCSV = true; | |
| if ( !isset($attachments) || !file_exists($attachments) ) $errorAttachments = true; | |
| if ( !isset($fileupload) || !file_exists($fileupload) ) $errorFileUpload = true; | |
| //Display the form again as there was ane rror | |
| if( $errorCSV || $errorAttachments || $errorFileUpload ) | |
| { | |
| showForm($errorCSV, $errorAttachments, $errorFileUpload); | |
| } | |
| else{ | |
| echo "<h3>Let's have a run!</h3> <br /><br />"; | |
| // form variables to former ruby variables | |
| $input_path = $csv; | |
| $source_images_path = $attachments; | |
| $dest_images_path = $fileupload; | |
| $dispersion_factor = 20;//$dispersion; | |
| // status message | |
| echo "<h3>Reading from ". $source_images_path . "</h3><br /><br />"; | |
| $path_to_id = array(); // new array | |
| // open CSV-file | |
| $handle = fopen ($input_path, "r"); | |
| // read file | |
| while (!feof($handle)) { | |
| $line = fgets($handle); | |
| // get infos - example for line: "FileUpload/2010/07/filename01.jpg";"3626" | |
| preg_match("/^\"(.+?)\";\"(\d+?)\"/", $line, $result); | |
| // if line is empty - error message and next line | |
| if (!isset($result)) { | |
| echo "No match for line" . $line . ",skipping"; | |
| continue; | |
| } | |
| //key is path to file, value is media_id | |
| $path_to_id[$result[1]] = $result[2]; | |
| } // End read file | |
| // Count records -> status message | |
| echo "<h3>" . count($path_to_id) . " records read.</h3><br /><br />"; | |
| echo '<div class="Report">'; | |
| $i = 0; | |
| foreach ($path_to_id as $path => $media_id){ | |
| $i++; | |
| $source_path = $path; | |
| // Sebi hat absoluten Pfad, $source_path = $source_images_path ."/". $path; //get path to source file | |
| $path_parts = pathinfo($source_path); // get extetion of the file | |
| $source_extention = $path_parts['extension']; | |
| $dispersion_id = $media_id % $dispersion_factor; // get dispersion_id | |
| $dest_dir = $dest_images_path . "/" . $dispersion_id; // get new folder + dispersion | |
| $dest_path = $dest_dir. "/" . $media_id . "." . $source_extention; //get new file path | |
| if ($debug == true && $i == 5) { | |
| echo "<hr><h2>DEBUG</h2><strong>i:</strong> $i <br /> <strong>source_image_path:</strong> $source_image_path <br /> <strong>media_id:</strong> $media_id <br /> <strong>source_path:</strong> $source_path <br /> <strong>path_parts:</strong> $path_parts <br /> <strong>source_extention:</strong> $source_extention <br /> <strong>dispersion_id:</strong> $dispersion_id <br /> <strong>dest_dir:</strong> $dest_dir <br /> <strong>dest_path:</strong> $dest_path<br /><hr>";} | |
| // Copying | |
| try { | |
| if (!file_exists($dest_dir) && $testrun != true) {mkdir($dest_dir);} | |
| if (file_exists($source_path)) { | |
| if ($testrun != true) { copy($source_path, $dest_path);} | |
| // Status message | |
| echo "<strong>$i</strong> | Copying: $source_path <strong> ---> </strong> $dest_path <br />"; | |
| } | |
| else { | |
| throw new Exception('Source file does not exist! File: <strong>'. $source_path . '</strong><br />'); | |
| } | |
| } | |
| catch (Exception $e) | |
| { | |
| echo '<strong>ERROR chaught:</strong> ', $e->getMessage(), "\n"; | |
| } | |
| } | |
| echo '</div>'; | |
| // status message | |
| echo "<br/><br /><h2>all done, all fine - have fun with fileUpload</h2>"; | |
| if ($testrun == true) echo "but this was only a test"; | |
| pageFooter(); | |
| } | |
| } | |
| ?> |
| <?php | |
| define('VERSION', '0.1'); | |
| /** | |
| * Vanilla Attachments to FileUpload Porter | |
| * This is not an official Vanilla Plugin, Layout was taken from Vanilla 2 Exporter | |
| * This script puts Vanilla1 Attachment files to Vanilla 2 FileUpload | |
| * see http://www.vanillaforums.org/discussion/13136/attachments-to-fileupload-importer for more information | |
| * The function of this script comes from user rayk. | |
| * brought to PHP and made more user friendly by user vegano | |
| */ | |
| /** | |
| * Debug Mode | |
| * set to true to see the values of the fifth file that should be copied | |
| */ | |
| $debug = true; | |
| /** | |
| * HTML header | |
| */ | |
| function PageHeader() { | |
| echo '<?xml version="1.0" encoding="UTF-8"?>'; | |
| ?> | |
| <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> | |
| <html> | |
| <head> | |
| <title>Vanilla Attachments to FileUpload Porter - Form Vanilla1 to Vanilla2</title> | |
| <style> | |
| body { | |
| font-family: 'lucida grande','Lucida Sans Unicode', tahoma, sans-serif; | |
| background: url('http://vanillaforums.com/porter/slicesplash.jpg') top center no-repeat #C7E6FB; | |
| margin: 0px; | |
| padding: 0px; | |
| text-align: center; | |
| color:#076C8E; | |
| text-shadow:0 1px 0 #FFFFFF; | |
| } | |
| a, | |
| a:link, | |
| a:active, | |
| a:visited { | |
| color: #2786C2; | |
| text-decoration: none; | |
| } | |
| a:hover { | |
| color: #FF0084 !important; | |
| text-decoration: underline; | |
| } | |
| div.Title { | |
| background:#E2F4FF none repeat scroll 0 0; | |
| border-top: 1px solid #A5D0E7; | |
| border-bottom: 1px solid #A5D0E7; | |
| margin: 50px 0; | |
| padding: 30px 0 4px; | |
| } | |
| div.Title h1 { | |
| text-align: left; | |
| width: 600px; | |
| margin: 0 auto; | |
| } | |
| div.Title img { | |
| top: 20px; | |
| position: absolute; | |
| } | |
| div.Title p { | |
| padding: 0 0 0 270px; | |
| margin: 0; | |
| font-size: 30px; | |
| } | |
| h1 { | |
| font-family: Arial, Helvetica, Verdana; | |
| color: #02455B; | |
| width: 568px; | |
| margin: 0 auto; | |
| padding: 0; | |
| font-size: 180%; | |
| } | |
| div.Form { | |
| text-align: center; | |
| width: 900px; | |
| margin: 0 auto; | |
| adding: 0; | |
| } | |
| div.Form ul { | |
| margin: auto; | |
| } | |
| div.Errors { | |
| background: #d00; | |
| padding: 20px 8px !important; | |
| margin: 0 0 10px; | |
| border-bottom: 1px solid #C0E7F5; | |
| } | |
| .Errors li { | |
| padding: 4px 0 !important; | |
| border: 0px !important; | |
| margin: 0px !important; | |
| color: #fff !important; | |
| font-size: 16px; | |
| line-height: 150%; | |
| text-shadow: #900 0 1px 0; | |
| } | |
| .Errors li pre, | |
| .Errors li code { | |
| border-radius: 3px; | |
| -moz-border-radius: 3px; | |
| -webkit-border-radius: 3px; | |
| border: 1px solid #b00; | |
| background: #c00; | |
| margin: 10px 0 0; | |
| padding: 4px 8px; | |
| display: block; | |
| text-shadow: none; | |
| font-size: 13px; | |
| font-weight: normal; | |
| font-family: monospace; | |
| } | |
| .Errors li a { | |
| color: #ffff00; | |
| text-decoration: underline; | |
| } | |
| .Errors li a:hover { | |
| color: #ff0 !important; | |
| text-decoration: none; | |
| } | |
| .Hidden { | |
| display: none; | |
| } | |
| /* Forms */ | |
| form { | |
| margin: 0 0 20px; | |
| text-align: right; | |
| } | |
| form ul { | |
| text-align: left; | |
| list-style: none; | |
| margin: 0px; | |
| padding: 10px; | |
| } | |
| form ul li { | |
| padding: 10px 0; | |
| font-size: 18px; | |
| } | |
| form ul li.Warning { | |
| padding-bottom: 0; | |
| border-bottom: 0; | |
| font-size: 17px; | |
| } | |
| form ul li.Warning div { | |
| font-size: 14px; | |
| line-height: 1.6; | |
| color: #000; | |
| text-shadow: none; | |
| padding: 16px 0 8px; | |
| } | |
| form label { | |
| font-family: Arial, Helvetica, Verdana; | |
| font-weight: bold; | |
| display: block; | |
| padding: 8px 0 0; | |
| font-size: 110%; | |
| color: #02455B; | |
| } | |
| form label span { | |
| font-size: 13px; | |
| color: #555; | |
| font-weight: normal; | |
| text-shadow: none; | |
| padding: 0 0 0 10px; | |
| } | |
| form select { | |
| border-radius: 4px; | |
| -moz-border-radius: 4px; | |
| -webkit-border-radius: 4px; | |
| font-size: 110%; | |
| padding: 8px; | |
| width: 496px; | |
| border: 1px solid #ccc; | |
| color: #555; | |
| } | |
| form input.InputBox { | |
| border-radius: 4px; | |
| -moz-border-radius: 4px; | |
| -webkit-border-radius: 4px; | |
| font-size: 110%; | |
| padding: 8px; | |
| width: 420px; | |
| border: 1px solid #ccc; | |
| color: #555; | |
| } | |
| form input.InputBox:focus { | |
| color: #000; | |
| background: #FFFEDE; | |
| border: 1px solid #aaa; | |
| } | |
| form li.Last { | |
| padding: 12px 0 2px; | |
| border-bottom: 0; | |
| } | |
| div.Button { | |
| text-align: right; | |
| padding: 12px 0 30px; | |
| width: 496px; | |
| margin: 0 auto; | |
| clear: both; | |
| } | |
| div.Button a, | |
| input.Button { | |
| cursor: pointer; | |
| font-family: arial, helvetica, verdana; | |
| font-size: 25px; | |
| font-weight: bold; | |
| color: #02475A; | |
| text-shadow: 0 1px 0 #fff; | |
| margin: 0; | |
| padding: 3px 10px; | |
| background: url('http://vanillaforums.com/porter/buttonbg.png') repeat-x center left #f8f8f8; | |
| border: 1px solid #999; | |
| border-radius: 3px; | |
| -moz-border-radius: 3px; | |
| -webkit-border-radius: 3px; | |
| box-shadow: 0px 0px 2px #999; | |
| -moz-box-shadow: 0px 0px 2px #999; | |
| -webkit-box-shadow: 0px 0px 2px #999; | |
| } | |
| div.Button a { | |
| padding: 4px 8px; | |
| } | |
| div.Button a:hover, | |
| input.Button:hover { | |
| text-decoration: none; | |
| color: #111; | |
| border: 1px solid #666; | |
| } | |
| div.Button a:focus, | |
| input.Button:focus { | |
| background: #eee; | |
| } | |
| div.Attachments, div.FileUpload { | |
| width: 440px; | |
| } | |
| div.Attachments { | |
| float: left; | |
| } | |
| div.FileUpload { | |
| float: right; | |
| } | |
| /* readme.html */ | |
| div.Info { | |
| text-align: left; | |
| width: 568px; | |
| margin: 0 auto 0px; | |
| font-size: 80%; | |
| line-height: 1.6; | |
| } | |
| div.Info h1 { | |
| padding: 6px 0 0; | |
| margin: 0; | |
| } | |
| div.Info p { | |
| color: #000; | |
| padding: 3px 0 6px; | |
| margin: 0; | |
| text-shadow: none; | |
| } | |
| div.Info li { | |
| color: #000; | |
| padding: 1px 0; | |
| margin: 0; | |
| text-shadow: none; | |
| } | |
| div.Report { | |
| font-size:70%; | |
| text-align: left; | |
| padding-left: 50px; | |
| } | |
| .Version { | |
| font-size: 9pt; | |
| font-weight: normal; | |
| } | |
| </style> | |
| <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script> | |
| <script type="text/javascript"> | |
| /* <![CDATA[ */ | |
| $(document).ready(function() { | |
| $("input[name='samedb']").change(function(){ | |
| if($(this).is(":checked")){ | |
| $(".FileUpload input[name='dbhost2'], .FileUpload input[name='dbuser2'], .FileUpload input[name='dbpass2']").css("background-color","ccc").attr("disabled", true); | |
| }else{ | |
| if($("input[name='sametable']").is(":checked")){ | |
| }else{ | |
| $(".FileUpload input[name='dbhost2'], .FileUpload input[name='dbuser2'], .FileUpload input[name='dbpass2']").css("background-color","#fff").attr("disabled", false); | |
| } } | |
| }); | |
| $("input[name='sametable']").change(function(){ | |
| if($(this).is(":checked")){ | |
| $(".FileUpload input[name='dbhost2'], .FileUpload input[name='dbuser2'], .FileUpload input[name='dbpass2'], .FileUpload input[name='dbname2']").css("background-color","ccc").attr("disabled", true); | |
| }else{ | |
| if($("input[name='samedb']").is(":checked")){ | |
| $(".FileUpload input[name='dbname2']").css("background-color","#fff").attr("disabled", false); | |
| }else{ | |
| $(".FileUpload input[name='dbhost2'], .FileUpload input[name='dbuser2'], .FileUpload input[name='dbpass2'], .FileUpload input[name='dbname2']").css("background-color","#fff").attr("disabled", false); | |
| }} | |
| }); | |
| if ($("input[name='samedb']").is(":checked")){ | |
| $(".FileUpload input[name='dbhost2'], .FileUpload input[name='dbuser2'], .FileUpload input[name='dbpass2']").css("background-color","ccc").attr("disabled", true); | |
| }; | |
| if ($("input[name='sametable']").is(":checked")){ | |
| $(".FileUpload input[name='dbhost2'], .FileUpload input[name='dbuser2'], .FileUpload input[name='dbpass2'], .FileUpload input[name='dbname2']").css("background-color","ccc").attr("disabled", true); | |
| }; | |
| }); | |
| /* ]]> */ | |
| </script> | |
| </head> | |
| <body> | |
| <div id="Frame"> | |
| <div id="Content"> | |
| <div class="Title"> | |
| <h1> | |
| <img src="http://vanillaforums.com/porter/vanilla_logo.png" alt="Vanilla" /> | |
| <p>Vanilla Attachments to FileUpload Porter <span class="Version">Version <?php echo VERSION; ?></span></p> | |
| </h1> | |
| </div> | |
| <?php | |
| } //PageHeader END | |
| /** | |
| * HTML footer | |
| */ | |
| function PageFooter() { | |
| ?> | |
| </div> | |
| </div> | |
| </body> | |
| </html> | |
| <?php | |
| } // PageFooter | |
| /** | |
| * Congratilations: After quit Export without Errors | |
| */ | |
| function ViewCongratulations($Files, $DbLines, $IsTestrun) { | |
| PageHeader(); | |
| ?> | |
| <div class="Info"> | |
| Everythings done - you are ready now<br /> | |
| <?php echo $DbLines; ?> Database Lines exported <br /> | |
| <?php echo $Files; ?> Files exported <br /> | |
| </div><br /> <br /> | |
| <div class="Info"> | |
| <h3>Thanks to</h3> | |
| <p>Many thanks for the first step goes to user <strong>rayk</strong> and his friend who is doing Ruby</p> | |
| <p>The second step - bring it to PHP and make a little bit of GUI - was done by user <strong>vegano</strong></p> | |
| <p>check <a href="http://vanillaforums.org/discussion/13136/attachments-to-fileupload-importer">http://vanillaforums.org/discussion/13136/attachments-to-fileupload-importer</a> for more information.</p> | |
| </div> | |
| <?php | |
| PageFooter(); | |
| } // ViewCongratulations | |
| /** | |
| * Form: Database connection info | |
| */ | |
| function ViewForm($Data) { | |
| if ($debug == true) print_r($Data); | |
| $msg = GetValue('Msg', $Data, ''); | |
| $status = GetValue('Status', $Data, ''); | |
| $DbPorted = $status['DB']; | |
| $FilePorted = $status['File']; | |
| PageHeader(); ?> | |
| <div class="Info"> | |
| Welcome to the Vanilla Attachments to FileUpload Porter. | |
| This application will export your existing Attachments of Vanilla 1 to FileUpload of Vanilla 2. <br />Please make sure the Plugin FileUpload is installed on a running installation of Vanilla 2. <br />You will have to know the login data of your database(s). May you have also to make some folders writeable. | |
| </div> | |
| <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> | |
| <input type="hidden" name="step" value="info" /> | |
| <div class="Form"> | |
| <?php if($msg!='') : ?> | |
| <div class="Messages Errors"> | |
| <ul> | |
| <li><?php echo $msg; ?></li> | |
| </ul> | |
| </div> | |
| <?php endif; ?> | |
| <div id="Vanilla1" class="Attachments"> | |
| <h3>Vanilla 1 - Attachments</h3> | |
| <ul> | |
| <li> | |
| <label>Van1 Table Prefix <span>Most installations have a database prefix, but if you're sure you don't have one you can leave this blank.</span></label> | |
| <input class="InputBox" type="text" name="prefix1" value="<?php echo urlencode(GetValue('prefix1')) ?>" /> | |
| </li> | |
| <li> | |
| <label>Van1 Database Name <span></span></label> | |
| <input class="InputBox" type="text" name="dbname1" value="<?php echo urlencode(GetValue('dbname1')) ?>" /> | |
| </li> | |
| <li> | |
| <label>Van1 Database Host <span>Database host is usually "localhost"</span></label> | |
| <input class="InputBox" type="text" name="dbhost1" value="<?php echo urlencode(GetValue('dbhost1', '', 'localhost')) ?>" /> | |
| </li> | |
| <li> | |
| <label>Van1 Database Username</label> | |
| <input class="InputBox" type="text" name="dbuser1" value="<?php echo urlencode(GetValue('dbuser1')) ?>" /> | |
| </li> | |
| <li> | |
| <label>Van1 Database Password</label> | |
| <input class="InputBox" type="password" name="dbpass1" value="<?php echo GetValue('dbpass1') ?>" /> | |
| </li> | |
| <li> | |
| <label> | |
| <input class="CheckBox" type="checkbox" name="samedb" value="samedb" <?php if(GetValue('samedb')) echo 'checked="checked"'; ?> /> Same Database<span> vanilla1 and vanilla 2 share the same database </span></label> | |
| <label> | |
| <input class="CheckBox" type="checkbox" name="sametable" value="sametable" <?php if(GetValue('sametable')) echo 'checked="checked"'; ?> /> Same Table<span> vanilla1 and vanilla 2 share the same table </span> | |
| </label> | |
| </li> | |
| <li> | |
| <label>Attachment Uploads Path <span>your Attachment plugin's upload directory (absolute path)<br />Example:<br /><strong>/home/site/public_html/forumdirectory/uploads</strong></span></label> | |
| <input class="InputBox" type="text" name="atpath" value="<?php echo GetValue('atpath') ?>" /> | |
| </li> | |
| </ul> | |
| </div> <!-- Vanilla1 End --> | |
| <div id="Vanilla2" class="FileUpload"> | |
| <h3>Vanilla 2 - FileUpload</h3> | |
| <ul> | |
| <li> | |
| <label>Van2 Table Prefix <span>Most installations have a database prefix, but if you're sure you don't have one you can leave this blank.</span></label> | |
| <input class="InputBox" type="text" name="prefix2" value="<?php echo urlencode(GetValue('prefix2','','gdn_')) ?>" /> | |
| </li> | |
| <li> | |
| <label>Van2 Database Name <span></span></label> | |
| <input class="InputBox" type="text" name="dbname2" value="<?php echo urlencode(GetValue('dbname2')) ?>" /> | |
| </li> | |
| <li> | |
| <label>Van2 Database Host <span>Database host is usually "localhost"</span></label> | |
| <input class="InputBox" type="text" name="dbhost2" value="<?php echo urlencode(GetValue('dbhost2', '', 'localhost')) ?>" /> | |
| </li> | |
| <li> | |
| <label>Van2 Database Username</label> | |
| <input class="InputBox" type="text" name="dbuser2" value="<?php echo urlencode(GetValue('dbuser2')) ?>" /> | |
| </li> | |
| <li> | |
| <label>Van2 Database Password</label> | |
| <input class="InputBox" type="password" name="dbpass2" value="<?php echo GetValue('dbpass2') ?>" /> | |
| </li> | |
| <li> | |
| <label>FileUpload Uploads Path <span>your FileUpload plugin's upload directory (absolute path)<br />Example:<br /><strong>/home/site/public_html/forumdirectory/uploads/FileUpload</strong></span></label> | |
| <input class="InputBox" type="text" name="fupath" value="<?php echo GetValue('fupath') ?>" /> | |
| </li> | |
| <li> | |
| <label title="check FileUploads option 'Plugin.FileUpload.DispersionFactor' for more informations">FileUpload: Dispersion Factor <span>leave default (20) if you don't know what it is for.</span></label> | |
| <input class="InputBox" type="text" name="dispersion" value="<?php echo GetValue('dispersion', '',20) ?>" /> | |
| </li> | |
| </ul> | |
| </div> <!-- Vanilla2 End --> | |
| <div class="Button"> | |
| <label><input class="CheckBox" type="checkbox" id="testrun" name="testrun" value="testrun" <?php if(GetValue('testrun')) echo 'checked="checked"'; ?> /> Testrun <span>doesn't copy files</span></label> | |
| <?php | |
| if ($DbPorted) echo "<input type=\"hidden\" name=\"DbPorted\" value=\"true\" />"; | |
| if ($FilePorted) echo "<input type=\"hidden\" name=\"FilePorted\" value=\"true\" />"; | |
| ?> | |
| <label><input class="Button" type="submit" name="submit" value="Begin Export" /></label> | |
| </div> | |
| </div> | |
| </form> | |
| <?php PageFooter(); | |
| } // Database Connect Info END | |
| /** | |
| * Function: GetValue | |
| */ | |
| function GetValue($Key, $Collection = NULL, $Default = '') { | |
| if(!$Collection) | |
| $Collection = $_POST; | |
| if(array_key_exists($Key, $Collection)) | |
| return $Collection[$Key]; | |
| return $Default; | |
| } // Get Value End | |
| /** Export the Attachments Database Entries to FileUpload Database */ | |
| class Exporter { | |
| /** @var array Database Van1 connection info */ | |
| protected $DbInfo1 = array(); | |
| /** @var array Database Van2 connection info */ | |
| protected $DbInfo2 = array(); | |
| /** @var array File path info */ | |
| protected $FileInfo = array(); | |
| /** Check if Testrun */ | |
| protected $IsTestrun = FALSE; | |
| /** Check if Same Database or Same Table is used */ | |
| protected $UseSameDatabase = FALSE; | |
| protected $UseSameTable = FALSE; | |
| /** Dispersion Factor of FileUpload - for more Information check FileUploads option 'Plugin.FileUpload.DispersionFactor', default set by FileUpload is 20 */ | |
| protected $DispersionFactor = 20; | |
| /** Status check */ | |
| protected $DbPorted = FALSE; | |
| protected $FilePorted = FALSE; | |
| /** Summery */ | |
| protected $ExportedLines = 0; | |
| protected $ExportedFiles = 0; | |
| /** Clean up */ | |
| protected $CleanUpFileNames = TRUE; //FALSE; | |
| /** | |
| * Construct and set the controller's properties from the posted form. | |
| */ | |
| public function __construct() { | |
| $this->HandleForm(); | |
| } | |
| /** | |
| * User submitted db connection info | |
| */ | |
| public function HandleForm() { | |
| $this->IsTestrun = array_key_exists('testrun', $_POST) ? TRUE : FALSE; // Is Testrun? | |
| $this->UseSameDatabase = (array_key_exists('samedb', $_POST) || ($_POST['dbuser1'] == $_POST['dbuser2'] && $_POST['dbhost1'] == $_POST['dbhost2'] && $_POST['dbpass1'] == $_POST['dbpass2'])) ? TRUE : FALSE; // Attachments and FileUpload have same Database? | |
| $this->UseSameTable = (array_key_exists('sametable', $_POST) || ($_POST['dbuser1'] == $_POST['dbuser2'] && $_POST['dbhost1'] == $_POST['dbhost2'] && $_POST['dbpass1'] == $_POST['dbpass2'] && $_POST['dbname1'] == $_POST['dbname2'])) ? TRUE : FALSE; // Attachments and FileUpload have same Table? | |
| $this->DispersionFactor = array_key_exists('dispersion', $_POST) ? $_POST['dispersion'] : 20; | |
| $this->DbPorted = array_key_exists('DbPorted', $_POST) ? $_POST['DbPorted'] : false; | |
| $this->FilePorted = array_key_exists('FilePorted', $_POST) ? $_POST['FilePorted'] : false; | |
| // Attachments Database | |
| $this->DbInfo1 = array( | |
| 'app' => 'Vanilla 1', | |
| 'dbhost' => $_POST['dbhost1'], | |
| 'dbuser' => $_POST['dbuser1'], | |
| 'dbpass' => $_POST['dbpass1'], | |
| 'dbname' => $_POST['dbname1'], | |
| 'table' => 'Attachment', | |
| 'prefix' => preg_replace('/[^A-Za-z0-9_-]/','',$_POST['prefix1'])); | |
| if($this->UseSameTable || $this->UseSameDatabase) { | |
| $_POST['dbhost2'] = $_POST['dbhost1']; | |
| $_POST['dbuser2'] = $_POST['dbuser1']; | |
| $_POST['dbpass2'] = $_POST['dbpass1']; | |
| if($this->UseSameTable) $_POST['dbname2'] = $_POST['dbname1']; | |
| } | |
| // FileUpload Database | |
| $this->DbInfo2 = array( | |
| 'app' => 'Vanilla 2', | |
| 'dbhost' => $_POST['dbhost2'], | |
| 'dbuser' => $_POST['dbuser2'], | |
| 'dbpass' => $_POST['dbpass2'], | |
| 'dbname' => $_POST['dbname2'], | |
| 'table' => 'Media', | |
| 'prefix' => preg_replace('/[^A-Za-z0-9_-]/','',$_POST['prefix2'])); | |
| if (substr($_POST['atpath'], -1) != "/"){ $_POST['atpath'] = $_POST['atpath'] . "/";}; | |
| if (substr($_POST['fupath'], -1) != "/"){ $_POST['fupath'] = $_POST['fupath'] . "/";}; | |
| $this->FileInfo = array( | |
| 'attachment' => $_POST['atpath'], | |
| 'fileupload' => $_POST['fupath'] | |
| ); | |
| } | |
| /** | |
| * Test database connection info | |
| */ | |
| public function TestDatabase($DbInfo) { | |
| // Connection | |
| if($C = @mysql_connect($DbInfo['dbhost'], $DbInfo['dbuser'], $DbInfo['dbpass'])) { | |
| // Check for Database | |
| if(mysql_select_db($DbInfo['dbname'], $C)) { | |
| // Check for attachment/media table | |
| $return = mysql_list_tables($DbInfo['dbname']); | |
| while ($row = mysql_fetch_row($return)) { | |
| $tables[] = $row[0]; | |
| } | |
| if (in_array($DbInfo['prefix'].$DbInfo['table'], $tables)) {mysql_close($C); | |
| return true; | |
| } | |
| else { | |
| mysql_close($C); | |
| return $DbInfo['app'] . ' database failure: Could not find table “'.$DbInfo['prefix'].$DbInfo['table'].'”. '; | |
| } | |
| } | |
| else { | |
| mysql_close($C); | |
| return $DbInfo['app'] . ' database failure: Could not find database “'.$DbInfo['dbname'].'”. '; | |
| } | |
| } | |
| else | |
| return $DbInfo['app'] . ' database failure: Could not connect to host “'.$DbInfo['dbhost'].'” as user “'.$DbInfo['dbuser'].'” with given password. '; | |
| } | |
| /** | |
| * Test file write permissions info | |
| */ | |
| public function TestFilePermission($FileInfo) { | |
| $return = ''; | |
| if(!is_readable($FileInfo['attachment'])) $return .= 'file permission error: Could not read for attachment directory at: ' . $FileInfo['attachment'] . '<br />'; | |
| if(!is_writable($FileInfo['fileupload'])) $return .= 'file permission error: Could not write to attachment directory at: ' . $FileInfo['fileupload'] . '<br />'; | |
| if ($return != '') return $return; | |
| return true; | |
| } | |
| /** | |
| * Execute Copying Files from Attachments to FileUpload | |
| */ | |
| public function ExportFiles($FileInfo, $DbInfo) { | |
| // Need Information from FileUpload Database | |
| $Connection = mysql_connect($DbInfo['dbhost'], $DbInfo['dbuser'], $DbInfo['dbpass']); | |
| mysql_select_db($DbInfo['dbname'], $Connection); | |
| $query = "SELECT MediaID, Path FROM $DbInfo[prefix]Media"; | |
| $Result = mysql_query($query, $Connection); | |
| if ($Result === FALSE) { | |
| trigger_error(mysql_error($Connection)); | |
| $Result = "Database Error: wasn't able to get information of FileUpload table (MediaId, Path) - query: " . $query; | |
| return $Result; | |
| } | |
| $FileLocation = array(); | |
| while ($row = mysql_fetch_array($Result, MYSQL_ASSOC)) { | |
| $FileLocation[$row['MediaID']] = $row['Path']; | |
| } | |
| mysql_free_result($Result); | |
| $this->ExportedFiles = ''; | |
| $Msg = ''; | |
| $i = 0; | |
| foreach ($FileLocation as $MediaID => $Path) { | |
| $i++; | |
| $OldFilePath = $Path; | |
| // Sebi hat absoluten Pfad, $OldFilePath = $FileInfo['attachment'] . "/" . $Path; //get path to source file | |
| $Path_Parts = pathinfo($OldFilePath); // get extetion of the file | |
| $FileExtention = $Path_Parts['extension']; | |
| $DispersionID = $MediaID % $this->DispersionFactor; // get dispersion_id | |
| $NewFileDirectory = $FileInfo['fileupload'] . $DispersionID; // get new folder + dispersion | |
| $NewFilePath = $NewFileDirectory . "/" . $MediaID . "." . $FileExtention; //get new file path | |
| // Copying files | |
| // Testrun? | |
| if ($this->IsTestrun) { | |
| if (file_exists($OldFilePath)) { | |
| $this->ExportedFiles .= "<strong>$i</strong> | Copying: " . $OldFilePath . " <strong> ---> </strong> " . $NewFilePath . "<br />"; | |
| } | |
| else { | |
| $this->ExportedFiles .= "<strong>Error</strong> | <strong>Not able to Copying</strong>: " . $OldFilePath . " <strong> ---> </strong> " . $NewFilePath . "<br />"; | |
| } | |
| } | |
| // Not Testrun? | |
| else { | |
| set_time_limit(30); | |
| if (!file_exists($NewFileDirectory)) { | |
| $NewDir = mkdir($NewFileDirectory); | |
| if ($NewDir !== true) $Msg .= "Permission Error: Wasn't able to create directory: " . $NewFileDirectory . "<br />"; | |
| } | |
| if (file_exists($OldFilePath)) { | |
| $CopyFile = copy($OldFilePath, $NewFilePath); | |
| if ($CopyFile !== true) $Msg .= "Copy Error: Wasn't able to copy File " . $OldFilePath . " to " . $NewFilePath . ".<br />"; | |
| } | |
| else { | |
| $Msg .= "File Error: File " . $OldFilePath . " doesn't exist, wasn't able to copy.<br />"; | |
| } | |
| } | |
| } | |
| unset($Path); | |
| unset($MediaID); | |
| if (!$this->IsTestrun) $this->ExportedFiles = $i; | |
| if ($Msg == '') return true; | |
| return $Msg; | |
| } | |
| /** | |
| * Export Controler | |
| * 1. check Database Connection + File Permission | |
| * 2. Export Database | |
| * 3. Export Filesystem | |
| * 4. Congratulate | |
| */ | |
| public function DoExport() { | |
| // Test connection | |
| if (!$this->DbPorted) { | |
| $Msg = $this->TestDatabase($this->DbInfo1); | |
| $Msg = ($Msg === true) ? $this->TestDatabase($this->DbInfo2) : $Msg . "<br />" . $this->TestDatabase($this->DbInfo2);} | |
| if (!$this->FilePorted) { | |
| $Msg = ($Msg === true) ? $this->TestFilePermission($this->FileInfo) : $Msg. "<br />" . $this->TestFilePermission($this->FileInfo); | |
| } | |
| if($Msg === true) { | |
| // TEST CLEAN UP FIX THIS | |
| // $this->FileNameCleaning($this->FileInfo, $this->DbInfo1); | |
| // Test src tables' existence structure | |
| if (!$this->DbPorted) { | |
| $Msg = $this->ExportDatabase($this->DbInfo1, $this->DbInfo2); | |
| } | |
| if ($Msg === true) { | |
| if (!$this->FilePorted) { | |
| if (!$this->Testrun){ | |
| $Msg = $this->ExportFiles($this->FileInfo, $this->DbInfo2);} | |
| else { | |
| $Msg = $this->ExportFiles($this->FileInfo, $this->DbInfo1);} | |
| } | |
| if ($Msg === true) { | |
| ViewCongratulations($this->ExportedFiles, $this->ExportedLines, $this->IsTextrun); | |
| } | |
| else { | |
| ViewForm(array('Msg' => $Msg, 'Status' => array('DB' => true, 'File' => false))); // Back to form with error | |
| } | |
| } | |
| else { | |
| ViewForm(array('Msg' => $Msg, 'Status' => array('DB' => false, 'File' => false))); // Back to form with error | |
| } | |
| } | |
| else { | |
| ViewForm(array('Msg' => $Msg, 'Status' => array('DB' => false, 'File' => false))); // Back to form with error | |
| } | |
| } | |
| public function ExportDatabase($DbInfo1, $DbInfo2) { | |
| if ($this->UseSameTable){ | |
| $query1 = "INSERT INTO $DbInfo2[prefix]Media (Name, Type, Size, StorageMethod, Path, InsertUserID, DateInserted, ForeignID, ForeignTable) SELECT Name, MimeType, Size, 'local', Path, UserID, DateCreated, CommentID, 'comment' from $DbInfo1[prefix]Attachment WHERE $DbInfo1[prefix]attachment.AttachmentID NOT IN(SELECT AttachmentID FROM $DbInfo1[prefix]attachment JOIN $DbInfo1[prefix]discussion ON $DbInfo1[prefix]attachment.DiscussionID = $DbInfo1[prefix]discussion.DiscussionID WHERE $DbInfo1[prefix]attachment.CommentID = $DbInfo1[prefix]discussion.FirstCommentID)"; | |
| $query2 = "INSERT INTO $DbInfo2[prefix]Media (Name, Type, Size, StorageMethod, Path, InsertUserID, DateInserted, ForeignID, ForeignTable) SELECT Name, MimeType, Size, 'local', Path, UserID, DateCreated, DiscussionID, 'discussion' from $DbInfo1[prefix]Attachment WHERE $DbInfo1[prefix]attachment.AttachmentID IN(SELECT AttachmentID FROM $DbInfo1[prefix]attachment JOIN $DbInfo1[prefix]discussion ON $DbInfo1[prefix]attachment.DiscussionID = $DbInfo1[prefix]discussion.DiscussionID WHERE $DbInfo1[prefix]attachment.CommentID = $DbInfo1[prefix]discussion.FirstCommentID)"; | |
| } | |
| elseif (!$this->UseSameTable && $this->UseSameDatabase) { | |
| $query1 = "INSERT INTO $DbInfo2[dbname].$DbInfo2[prefix]Media (Name, Type, Size, StorageMethod, Path, InsertUserID, DateInserted, ForeignID, ForeignTable) SELECT Name, MimeType, Size, 'local', Path, UserID, DateCreated, CommentID, 'comment' from $DbInfo1[dbname].$DbInfo1[prefix]Attachment WHERE $DbInfo1[dbname].$DbInfo1[prefix]attachment.AttachmentID NOT IN(SELECT AttachmentID FROM $DbInfo1[dbname].$DbInfo1[prefix]attachment JOIN $DbInfo1[dbname].$DbInfo1[prefix]discussion ON $DbInfo1[dbname].$DbInfo1[prefix]attachment.DiscussionID = $DbInfo1[dbname].$DbInfo1[prefix]discussion.DiscussionID WHERE $DbInfo1[dbname].$DbInfo1[prefix]attachment.CommentID = $DbInfo1[dbname].$DbInfo1[prefix]discussion.FirstCommentID)"; | |
| $query2 = "INSERT INTO $DbInfo2[dbname].$DbInfo2[prefix]Media (Name, Type, Size, StorageMethod, Path, InsertUserID, DateInserted, ForeignID, ForeignTable) SELECT Name, MimeType, Size, 'local', Path, UserID, DateCreated, DiscussionID, 'discussion' from $DbInfo1[dbname].$DbInfo1[prefix]Attachment WHERE $DbInfo1[dbname].$DbInfo1[prefix]attachment.AttachmentID IN(SELECT AttachmentID FROM $DbInfo1[dbname].$DbInfo1[prefix]attachment JOIN $DbInfo1[dbname].$DbInfo1[prefix]discussion ON $DbInfo1[dbname].$DbInfo1[prefix]attachment.DiscussionID = $DbInfo1[dbname].$DbInfo1[prefix]discussion.DiscussionID WHERE $DbInfo1[dbname].$DbInfo1[prefix]attachment.CommentID = $DbInfo1[dbname].$DbInfo1[prefix]discussion.FirstCommentID)"; | |
| } | |
| else { | |
| $queryOut1 = "SELECT Name, MimeType, Size, 'local', Path, UserID, DateCreated, CommentID, 'comment' from $DbInfo1[prefix]Attachment WHERE $DbInfo1[prefix]attachment.AttachmentID NOT IN(SELECT AttachmentID FROM $DbInfo1[prefix]attachment JOIN $DbInfo1[prefix]discussion ON $DbInfo1[prefix]attachment.DiscussionID = $DbInfo1[prefix]discussion.DiscussionID WHERE $DbInfo1[prefix]attachment.CommentID = $DbInfo1[prefix]discussion.FirstCommentID)"; | |
| $queryIn1 = "INSERT INTO $DbInfo2[prefix]Media (Name, Type, Size, StorageMethod, Path, InsertUserID, DateInserted, ForeignID, ForeignTable)"; | |
| $queryOut2 = "SELECT Name, MimeType, Size, 'local', Path, UserID, DateCreated, DiscussionID, 'discussion', DateCreated from $DbInfo1[prefix]Attachment WHERE $DbInfo1[prefix]attachment.AttachmentID IN(SELECT AttachmentID FROM $DbInfo1[prefix]attachment JOIN $DbInfo1[prefix]discussion ON $DbInfo1[prefix]attachment.DiscussionID = $DbInfo1[prefix]discussion.DiscussionID WHERE $DbInfo1[prefix]attachment.CommentID = $DbInfo1[prefix]discussion.FirstCommentID)"; | |
| $queryIn2 = "INSERT INTO $DbInfo2[prefix]Media (Name, Type, Size, StorageMethod, Path, InsertUserID, DateInserted, ForeignID, ForeignTable)"; | |
| } | |
| if ($this->IsTestrun) { | |
| $this->ExportedLines = $query1 . "<br />" . $query2; | |
| return true; | |
| } | |
| if ($this->UseSameTable || $this->UseSameDatabase){ | |
| $Connection = mysql_connect($this->DbInfo1['dbhost'], $this->DbInfo1['dbuser'], $this->DbInfo1['dbpass']); | |
| mysql_select_db($this->DbInfo1['dbname'], $Connection); | |
| $Result1 = mysql_query($query1, $Connection); | |
| $ExportedLines1 = mysql_affected_rows(); | |
| if ($Result1 === FALSE) { | |
| trigger_error(mysql_error($Connection)); | |
| $Result1 = "Export failed on database issues - query1: " . $query1; | |
| } | |
| $Result2 = mysql_query($query2, $Connection); | |
| $ExportedLines2 = mysql_affected_rows(); | |
| if ($Result2 === FALSE) { | |
| trigger_error(mysql_error($Connection)); | |
| $Result2 = "Export failed on database issues - query2: ". $query2; | |
| } | |
| if ($Result1 != TRUE || $Result2 != TRUE){ | |
| return $Result1 . $Result2; | |
| } | |
| else { | |
| $this->ExportedLines = $ExportedLines1 + $ExportedLines2; | |
| return true; | |
| } | |
| } | |
| return true; | |
| } | |
| } | |
| // Instantiate the appropriate controller or display the input page. | |
| if(isset($_POST['submit'])) { | |
| // Mini-Factory | |
| $Controller = new Exporter(); | |
| $Controller->DoExport(); | |
| } | |
| else { | |
| ViewForm(array('Msg' => '')); | |
| } |
| <?php | |
| define('VERSION', '0.1'); | |
| /** | |
| * Vanilla Attachments to FileUpload Porter | |
| * This is not an official Vanilla Plugin, Layout was taken from Vanilla 2 Exporter | |
| * This script puts Vanilla1 Attachment files to Vanilla 2 FileUpload | |
| * see http://www.vanillaforums.org/discussion/13136/attachments-to-fileupload-importer for more information | |
| * The function of this script comes from user rayk. | |
| * brought to PHP and made more user friendly by user vegano | |
| */ | |
| /** | |
| * Debug Mode | |
| * set to true to see the values of the fifth file that should be copied | |
| */ | |
| $debug = true; | |
| /** | |
| * HTML header | |
| */ | |
| function PageHeader() { | |
| ?> | |
| <?xml version="1.0" encoding="UTF-8"?> | |
| <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> | |
| <html> | |
| <head> | |
| <title>Vanilla Attachments to FileUpload Porter - Form Vanilla1 to Vanilla2</title> | |
| <style> | |
| body { | |
| font-family: 'lucida grande','Lucida Sans Unicode', tahoma, sans-serif; | |
| background: url('http://vanillaforums.com/porter/slicesplash.jpg') top center no-repeat #C7E6FB; | |
| margin: 0px; | |
| padding: 0px; | |
| text-align: center; | |
| color:#076C8E; | |
| text-shadow:0 1px 0 #FFFFFF; | |
| } | |
| a, | |
| a:link, | |
| a:active, | |
| a:visited { | |
| color: #2786C2; | |
| text-decoration: none; | |
| } | |
| a:hover { | |
| color: #FF0084 !important; | |
| text-decoration: underline; | |
| } | |
| div.Title { | |
| background:#E2F4FF none repeat scroll 0 0; | |
| border-top: 1px solid #A5D0E7; | |
| border-bottom: 1px solid #A5D0E7; | |
| margin: 50px 0; | |
| padding: 30px 0 4px; | |
| } | |
| div.Title h1 { | |
| text-align: left; | |
| width: 600px; | |
| margin: 0 auto; | |
| } | |
| div.Title img { | |
| top: 20px; | |
| position: absolute; | |
| } | |
| div.Title p { | |
| padding: 0 0 0 270px; | |
| margin: 0; | |
| font-size: 30px; | |
| } | |
| h1 { | |
| font-family: Arial, Helvetica, Verdana; | |
| color: #02455B; | |
| width: 568px; | |
| margin: 0 auto; | |
| padding: 0; | |
| font-size: 180%; | |
| } | |
| div.Form { | |
| text-align: center; | |
| width: 900px; | |
| margin: 0 auto; | |
| adding: 0; | |
| } | |
| div.Form ul { | |
| width: 80%; | |
| margin: auto; | |
| } | |
| div.Errors { | |
| background: #d00; | |
| padding: 20px 8px !important; | |
| margin: 0 0 10px; | |
| border-bottom: 1px solid #C0E7F5; | |
| } | |
| .Errors li { | |
| padding: 4px 0 !important; | |
| border: 0px !important; | |
| margin: 0px !important; | |
| color: #fff !important; | |
| font-size: 16px; | |
| line-height: 150%; | |
| text-shadow: #900 0 1px 0; | |
| } | |
| .Errors li pre, | |
| .Errors li code { | |
| border-radius: 3px; | |
| -moz-border-radius: 3px; | |
| -webkit-border-radius: 3px; | |
| border: 1px solid #b00; | |
| background: #c00; | |
| margin: 10px 0 0; | |
| padding: 4px 8px; | |
| display: block; | |
| text-shadow: none; | |
| font-size: 13px; | |
| font-weight: normal; | |
| font-family: monospace; | |
| } | |
| .Errors li a { | |
| color: #ffff00; | |
| text-decoration: underline; | |
| } | |
| .Errors li a:hover { | |
| color: #ff0 !important; | |
| text-decoration: none; | |
| } | |
| .Hidden { | |
| display: none; | |
| } | |
| /* Forms */ | |
| form { | |
| margin: 0 0 20px; | |
| text-align: right; | |
| } | |
| form ul { | |
| text-align: left; | |
| list-style: none; | |
| margin: 0px; | |
| padding: 10px; | |
| } | |
| form ul li { | |
| padding: 10px 0; | |
| font-size: 18px; | |
| } | |
| form ul li.Warning { | |
| padding-bottom: 0; | |
| border-bottom: 0; | |
| font-size: 17px; | |
| } | |
| form ul li.Warning div { | |
| font-size: 14px; | |
| line-height: 1.6; | |
| color: #000; | |
| text-shadow: none; | |
| padding: 16px 0 8px; | |
| } | |
| form label { | |
| font-family: Arial, Helvetica, Verdana; | |
| font-weight: bold; | |
| display: block; | |
| padding: 8px 0 0; | |
| font-size: 110%; | |
| color: #02455B; | |
| } | |
| form label span { | |
| font-size: 13px; | |
| color: #555; | |
| font-weight: normal; | |
| text-shadow: none; | |
| padding: 0 0 0 10px; | |
| } | |
| form select { | |
| border-radius: 4px; | |
| -moz-border-radius: 4px; | |
| -webkit-border-radius: 4px; | |
| font-size: 110%; | |
| padding: 8px; | |
| width: 496px; | |
| border: 1px solid #ccc; | |
| color: #555; | |
| } | |
| form input.InputBox { | |
| border-radius: 4px; | |
| -moz-border-radius: 4px; | |
| -webkit-border-radius: 4px; | |
| font-size: 110%; | |
| padding: 8px; | |
| width: 420px; | |
| border: 1px solid #ccc; | |
| color: #555; | |
| } | |
| form input.InputBox:focus { | |
| color: #000; | |
| background: #FFFEDE; | |
| border: 1px solid #aaa; | |
| } | |
| form li.Last { | |
| padding: 12px 0 2px; | |
| border-bottom: 0; | |
| } | |
| div.Button { | |
| text-align: right; | |
| padding: 12px 0 30px; | |
| width: 496px; | |
| margin: 0 auto; | |
| clear: both; | |
| } | |
| div.Button a, | |
| input.Button { | |
| cursor: pointer; | |
| font-family: arial, helvetica, verdana; | |
| font-size: 25px; | |
| font-weight: bold; | |
| color: #02475A; | |
| text-shadow: 0 1px 0 #fff; | |
| margin: 0; | |
| padding: 3px 10px; | |
| background: url('http://vanillaforums.com/porter/buttonbg.png') repeat-x center left #f8f8f8; | |
| border: 1px solid #999; | |
| border-radius: 3px; | |
| -moz-border-radius: 3px; | |
| -webkit-border-radius: 3px; | |
| box-shadow: 0px 0px 2px #999; | |
| -moz-box-shadow: 0px 0px 2px #999; | |
| -webkit-box-shadow: 0px 0px 2px #999; | |
| } | |
| div.Button a { | |
| padding: 4px 8px; | |
| } | |
| div.Button a:hover, | |
| input.Button:hover { | |
| text-decoration: none; | |
| color: #111; | |
| border: 1px solid #666; | |
| } | |
| div.Button a:focus, | |
| input.Button:focus { | |
| background: #eee; | |
| } | |
| div.Attachments, div.FileUpload { | |
| width: 440px; | |
| } | |
| div.Attachments { | |
| float: left; | |
| } | |
| div.FileUpload { | |
| float: right; | |
| } | |
| /* readme.html */ | |
| div.Info { | |
| text-align: left; | |
| width: 568px; | |
| margin: 0 auto 0px; | |
| font-size: 80%; | |
| line-height: 1.6; | |
| } | |
| div.Info h1 { | |
| padding: 6px 0 0; | |
| margin: 0; | |
| } | |
| div.Info p { | |
| color: #000; | |
| padding: 3px 0 6px; | |
| margin: 0; | |
| text-shadow: none; | |
| } | |
| div.Info li { | |
| color: #000; | |
| padding: 1px 0; | |
| margin: 0; | |
| text-shadow: none; | |
| } | |
| code { | |
| font-size: 120%; | |
| font-family: Greorgia, Courier New, serif; | |
| } | |
| div.Code { | |
| background-color: #fff; | |
| border-radius: 4px; | |
| -moz-border-radius: 4px; | |
| -webkit-border-radius: 4px; | |
| padding: 8px; | |
| border: 1px solid #ccc; | |
| color: #555; | |
| } | |
| div.Report { | |
| font-size:70%; | |
| text-align: left; | |
| padding-left: 50px; | |
| } | |
| .Version { | |
| font-size: 9pt; | |
| font-weight: normal; | |
| } | |
| </style> | |
| <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script> | |
| <script type="text/javascript"> | |
| /* <![CDATA[ */ | |
| $(document).ready(function() { | |
| $("input[name='samedb']").change(function(){ | |
| if($(this).is(":checked")){ | |
| $(".FileUpload input[name='dbhost2'], .FileUpload input[name='dbuser2'], .FileUpload input[name='dbpass2']").css("background-color","ccc").attr("disabled", true); | |
| }else{ | |
| if($("input[name='sametable']").is(":checked")){ | |
| }else{ | |
| $(".FileUpload input[name='dbhost2'], .FileUpload input[name='dbuser2'], .FileUpload input[name='dbpass2']").css("background-color","#fff").attr("disabled", false); | |
| } } | |
| }); | |
| $("input[name='sametable']").change(function(){ | |
| if($(this).is(":checked")){ | |
| $(".FileUpload input[name='dbhost2'], .FileUpload input[name='dbuser2'], .FileUpload input[name='dbpass2'], .FileUpload input[name='dbname2']").css("background-color","ccc").attr("disabled", true); | |
| }else{ | |
| if($("input[name='samedb']").is(":checked")){ | |
| $(".FileUpload input[name='dbname2']").css("background-color","#fff").attr("disabled", false); | |
| }else{ | |
| $(".FileUpload input[name='dbhost2'], .FileUpload input[name='dbuser2'], .FileUpload input[name='dbpass2'], .FileUpload input[name='dbname2']").css("background-color","#fff").attr("disabled", false); | |
| }} | |
| }); | |
| if ($("input[name='samedb']").is(":checked")){ | |
| $(".FileUpload input[name='dbhost2'], .FileUpload input[name='dbuser2'], .FileUpload input[name='dbpass2']").css("background-color","ccc").attr("disabled", true); | |
| }; | |
| if ($("input[name='sametable']").is(":checked")){ | |
| $(".FileUpload input[name='dbhost2'], .FileUpload input[name='dbuser2'], .FileUpload input[name='dbpass2'], .FileUpload input[name='dbname2']").css("background-color","ccc").attr("disabled", true); | |
| }; | |
| }); | |
| /* ]]> */ | |
| </script> | |
| </head> | |
| <body> | |
| <div id="Frame"> | |
| <div id="Content"> | |
| <div class="Title"> | |
| <h1> | |
| <img src="http://vanillaforums.com/porter/vanilla_logo.png" alt="Vanilla" /> | |
| <p>Vanilla Attachments to FileUpload Porter - Form Vanilla1 to Vanilla2 <span class="Version">Version <?php echo VERSION; ?></span></p> | |
| </h1> | |
| </div> | |
| <?php | |
| } //PageHeader END | |
| /** | |
| * HTML footer | |
| */ | |
| function PageFooter() { | |
| ?> | |
| <div class="Thanks"> | |
| <p>Many thanks for the first step goes to user <strong>rayk</strong> and his friend who is doing Ruby</p> | |
| <p>The second step - bring it to PHP and make a little bit of GUI - was done by user <strong>vegano</strong></p> | |
| <p>check <a href="http://vanillaforums.org/discussion/13136/attachments-to-fileupload-importer">http://vanillaforums.org/discussion/13136/attachments-to-fileupload-importer</a> for more information.</p> | |
| </div> | |
| </div> | |
| </div> | |
| </body> | |
| </html> | |
| <?php | |
| } // PageFooter | |
| /** | |
| * Form: Database connection info | |
| */ | |
| function ViewForm($Data) { | |
| if ($debug == true) print_r($Data); | |
| echo $_POST['dbname1']; | |
| $msg = GetValue('Msg', $Data, ''); | |
| $Info = GetValue('Info', $Data, ''); | |
| $CanWrite = GetValue('CanWrite', $Data, NULL); | |
| if($CanWrite === NULL) | |
| $CanWrite = TestWrite(); | |
| PageHeader(); ?> | |
| <div class="Info"> | |
| Welcome to the Vanilla Attachments to FileUpload Porter. | |
| This application will export your existing Attachments of Vanilla 1 to FileUpload of Vanilla 2. <br />Please make sure the Plugin FileUpload is installed on a running installation of Vanilla 2. <br />You will have to know the login data of your database(s). May you have also to make some folders writeable. | |
| </div> | |
| <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> | |
| <input type="hidden" name="step" value="info" /> | |
| <div class="Form"> | |
| <?php if($msg!='') : ?> | |
| <div class="Messages Errors"> | |
| <ul> | |
| <li><?php echo $msg; ?></li> | |
| </ul> | |
| </div> | |
| <?php endif; ?> | |
| <div id="Vanilla1" class="Attachments"> | |
| <h3>Vanilla 1 - Attachments</h3> | |
| <ul> | |
| <li> | |
| <label>Van1 Table Prefix <span>Most installations have a database prefix, but if you're sure you don't have one you can leave this blank.</span></label> | |
| <input class="InputBox" type="text" name="prefix1" value="<?php echo urlencode(GetValue('prefix1','','lum_')) ?>" /> | |
| </li> | |
| <li> | |
| <label>Van1 Database Name <span>default of Attachments is "attachment"</span></label> | |
| <input class="InputBox" type="text" name="dbname1" value="<?php echo urlencode(GetValue('dbname1','','forum')) ?>" /> | |
| </li> | |
| <li> | |
| <label>Van1 Database Host <span>Database host is usually "localhost"</span></label> | |
| <input class="InputBox" type="text" name="dbhost1" value="<?php echo urlencode(GetValue('dbhost1', '', 'localhost')) ?>" /> | |
| </li> | |
| <li> | |
| <label>Van1 Database Username</label> | |
| <input class="InputBox" type="text" name="dbuser1" value="<?php echo urlencode(GetValue('dbuser1','','root')) ?>" /> | |
| </li> | |
| <li> | |
| <label>Van1 Database Password</label> | |
| <input class="InputBox" type="password" name="dbpass1" value="<?php echo GetValue('dbpass1') ?>" /> | |
| </li> | |
| <li> | |
| <label> | |
| <input class="CheckBox" type="checkbox" name="samedb" value="samedb" <?php if(GetValue('samedb')) echo 'checked="checked"'; ?> /> Same Database<span> vanilla1 and vanilla 2 share the same database </span></label> | |
| <label> | |
| <input class="CheckBox" type="checkbox" name="sametable" value="sametable" <?php if(GetValue('sametable')) echo 'checked="checked"'; ?> /> Same Table<span> vanilla1 and vanilla 2 share the same table </span> | |
| </label> | |
| </li> | |
| </ul> | |
| </div> <!-- Vanilla1 End --> | |
| <div id="Vanilla2" class="FileUpload"> | |
| <h3>Vanilla 2 - FileUpload</h3> | |
| <ul> | |
| <li> | |
| <label>Van2 Table Prefix <span>Most installations have a database prefix, but if you're sure you don't have one you can leave this blank.</span></label> | |
| <input class="InputBox" type="text" name="prefix2" value="<?php echo urlencode(GetValue('prefix2','','gdn_')) ?>" /> | |
| </li> | |
| <li> | |
| <label>Van2 Database Name <span>default of FileUpload is "media"</span></label> | |
| <input class="InputBox" type="text" name="dbname2" value="<?php echo urlencode(GetValue('dbname2', '', 'forum2')) ?>" /> | |
| </li> | |
| <li> | |
| <label>Van2 Database Host <span>Database host is usually "localhost"</span></label> | |
| <input class="InputBox" type="text" name="dbhost2" value="<?php echo urlencode(GetValue('dbhost2', '', 'localhost')) ?>" /> | |
| </li> | |
| <li> | |
| <label>Van2 Database Username</label> | |
| <input class="InputBox" type="text" name="dbuser2" value="<?php echo urlencode(GetValue('dbuser2','','root')) ?>" /> | |
| </li> | |
| <li> | |
| <label>Van2 Database Password</label> | |
| <input class="InputBox" type="password" name="dbpass2" value="<?php echo GetValue('dbpass2') ?>" /> | |
| </li> | |
| <li> | |
| <label title="check FileUploads option 'Plugin.FileUpload.DispersionFactor' for more informations">FileUpload: Dispersion Factor <span>leave default (20) if you don't know what it is for.</span></label> | |
| <input class="InputBox" type="text" name="dispersion" value="<?php echo GetValue('dispersion', '',20) ?>" /> | |
| </li> | |
| </ul> | |
| </div> <!-- Vanilla2 End --> | |
| <div class="Button"> | |
| <label><input class="CheckBox" type="checkbox" id="testrun" name="testrun" value="testrun" <?php if(GetValue('testrun')) echo 'checked="checked"'; ?> /> Testrun <span>doesn't copy files</span></label> | |
| <label><input class="Button" type="submit" name="submit" value="Begin Export" /></label> | |
| </div> | |
| </div> | |
| </form> | |
| <?php PageFooter(); | |
| } // Database Connect Info END | |
| /** | |
| * Function: GetValue | |
| */ | |
| function GetValue($Key, $Collection = NULL, $Default = '') { | |
| if(!$Collection) | |
| $Collection = $_POST; | |
| if(array_key_exists($Key, $Collection)) | |
| return $Collection[$Key]; | |
| return $Default; | |
| } // Get Value End | |
| /** Export the Attachments Database Entries to FileUpload Database */ | |
| class DbHandling { | |
| /** @var array Database Van1 connection info */ | |
| protected $DbInfo1 = array(); | |
| /** @var array Database Van2 connection info */ | |
| protected $DbInfo2 = array(); | |
| protected $IsTestrun = FALSE; | |
| protected $UseSameDatabase = FALSE; | |
| protected $UseSameTable = FALSE; | |
| /** | |
| * Construct and set the controller's properties from the posted form. | |
| */ | |
| public function __construct() { | |
| $this->HandleInfoForm(); | |
| } | |
| /** | |
| * User submitted db connection info | |
| */ | |
| public function HandleInfoForm() { | |
| $this->IsTestrun = array_key_exists('testrun', $_POST) ? TRUE : FALSE; // Is Testrun? | |
| $this->UseSameDatabase = (array_key_exists('samedb', $_POST) || ($_POST['dbuser1'] == $_POST['dbuser2'] && $_POST['dbhost1'] == $_POST['dbhost2'] && $_POST['dbpass1'] == $_POST['dbpass2'])) ? TRUE : FALSE; // Attachments and FileUpload have same Database? | |
| $this->UseSameTable = (array_key_exists('sametable', $_POST) || ($_POST['dbuser1'] == $_POST['dbuser2'] && $_POST['dbhost1'] == $_POST['dbhost2'] && $_POST['dbpass1'] == $_POST['dbpass2'] && $_POST['dbname1'] == $_POST['dbname2'])) ? TRUE : FALSE; // Attachments and FileUpload have same Table? | |
| $this->DispersionFactor = array_key_exists('dispersion', $_POST) ? $_POST['dispersion'] : 20; | |
| // Attachments Database | |
| $this->DbInfo1 = array( | |
| 'app' => 'Vanilla 1', | |
| 'dbhost' => $_POST['dbhost1'], | |
| 'dbuser' => $_POST['dbuser1'], | |
| 'dbpass' => $_POST['dbpass1'], | |
| 'dbname' => $_POST['dbname1'], | |
| 'table' => 'attachment', | |
| 'prefix' => preg_replace('/[^A-Za-z0-9_-]/','',$_POST['prefix1'])); | |
| if($this->UseSameTable || $this->UseSameDatabase) { | |
| $_POST['dbhost2'] = $_POST['dbhost1']; | |
| $_POST['dbuser2'] = $_POST['dbuser1']; | |
| $_POST['dbpass2'] = $_POST['dbpass1']; | |
| if($this->UseSameTable) $_POST['dbname2'] = $_POST['dbname1']; | |
| } | |
| // FileUpload Database | |
| $this->DbInfo2 = array( | |
| 'app' => 'Vanilla 2', | |
| 'dbhost' => $_POST['dbhost2'], | |
| 'dbuser' => $_POST['dbuser2'], | |
| 'dbpass' => $_POST['dbpass2'], | |
| 'dbname' => $_POST['dbname2'], | |
| 'table' => 'media', | |
| 'prefix' => preg_replace('/[^A-Za-z0-9_-]/','',$_POST['prefix2'])); } | |
| /** | |
| * Test database connection info | |
| */ | |
| public function TestDatabase($DbInfo) { | |
| // Connection | |
| if($C = @mysql_connect($DbInfo['dbhost'], $DbInfo['dbuser'], $DbInfo['dbpass'])) { | |
| // Check for Database | |
| if(mysql_select_db($DbInfo['dbname'], $C)) { | |
| // Check for attachment/media table | |
| $return = mysql_list_tables($DbInfo['dbname']); | |
| while ($row = mysql_fetch_row($return)) { | |
| $tables[] = $row[0]; | |
| } | |
| if (in_array($DbInfo['prefix'].$DbInfo['table'], $tables)) {mysql_close($C); | |
| return true; | |
| } | |
| else { | |
| mysql_close($C); | |
| return $DbInfo['app'] . ' database failure: Could not find table “'.$DbInfo['prefix'].$DbInfo['table'].'”. '; | |
| } | |
| } | |
| else { | |
| mysql_close($C); | |
| return $DbInfo['app'] . ' database failure: Could not find database “'.$DbInfo['dbname'].'”. '; | |
| } | |
| } | |
| else | |
| return $DbInfo['app'] . ' database failure: Could not connect to host “'.$DbInfo['dbhost'].'” as user “'.$DbInfo['dbuser'].'” with given password. '; | |
| } | |
| public function DoExport() { | |
| // Test connection | |
| $Msg = $this->TestDatabase($this->DbInfo1); | |
| $Msg = ($Msg === true) ? $this->TestDatabase($this->DbInfo2) : $Msg . "<br />" . $this->TestDatabase($this->DbInfo2); | |
| if($Msg === true) { | |
| // Test src tables' existence structure | |
| $Msg = $this->ExecuteQuery($this->DbInfo1, $this->DbInfo2); | |
| if ($Msg === true) { | |
| ViewForm(array('Msg' => 'Database transfere passed', 'Info' => $this->DbInfo1)); // Back to form with gratulation | |
| } | |
| else { | |
| ViewForm(array('Msg' => $Msg, 'Info' => $this->DbInfo1)); // Back to form with error | |
| } | |
| } | |
| else { | |
| ViewForm(array('Msg' => $Msg, 'Info' => $this->DbInfo1)); // Back to form with error | |
| } | |
| } | |
| public function ExecuteQuery($DbInfo1, $DbInfo2) { | |
| if ($this->UseSameTable){ | |
| $query1 = "INSERT INTO $DbInfo2[prefix]Media (Name, Type, Size, StorageMethod, Path, InsertUserID, DateInserted, ForeignID, ForeignTable) SELECT Name, MimeType, Size, 'local', Path, UserID, DateCreated, CommentID, 'comment' from $DbInfo1[prefix]Attachment WHERE $DbInfo1[prefix]attachment.AttachmentID NOT IN(SELECT AttachmentID FROM $DbInfo1[prefix]attachment JOIN $DbInfo1[prefix]discussion ON $DbInfo1[prefix]attachment.DiscussionID = $DbInfo1[prefix]discussion.DiscussionID WHERE $DbInfo1[prefix]attachment.CommentID = $DbInfo1[prefix]discussion.FirstCommentID)"; | |
| $query2 = "INSERT INTO $DbInfo2[prefix]Media (Name, Type, Size, StorageMethod, Path, InsertUserID, DateInserted, ForeignID, ForeignTable) SELECT Name, MimeType, Size, 'local', Path, UserID, DateCreated, DiscussionID, 'discussion' from $DbInfo1[prefix]Attachment WHERE $DbInfo1[prefix]attachment.AttachmentID IN(SELECT AttachmentID FROM $DbInfo1[prefix]attachment JOIN $DbInfo1[prefix]discussion ON $DbInfo1[prefix]attachment.DiscussionID = $DbInfo1[prefix]discussion.DiscussionID WHERE $DbInfo1[prefix]attachment.CommentID = $DbInfo1[prefix]discussion.FirstCommentID)"; | |
| } | |
| elseif (!$this->UseSameTable && $this->UseSameDatabase) { | |
| $query1 = "INSERT INTO $DbInfo2[dbname].$DbInfo2[prefix]Media (Name, Type, Size, StorageMethod, Path, InsertUserID, DateInserted, ForeignID, ForeignTable) SELECT Name, MimeType, Size, 'local', Path, UserID, DateCreated, CommentID, 'comment' from $DbInfo1[dbname].$DbInfo1[prefix]Attachment WHERE $DbInfo1[dbname].$DbInfo1[prefix]attachment.AttachmentID NOT IN(SELECT AttachmentID FROM $DbInfo1[dbname].$DbInfo1[prefix]attachment JOIN $DbInfo1[dbname].$DbInfo1[prefix]discussion ON $DbInfo1[dbname].$DbInfo1[prefix]attachment.DiscussionID = $DbInfo1[dbname].$DbInfo1[prefix]discussion.DiscussionID WHERE $DbInfo1[dbname].$DbInfo1[prefix]attachment.CommentID = $DbInfo1[dbname].$DbInfo1[prefix]discussion.FirstCommentID)"; | |
| $query2 = "INSERT INTO $DbInfo2[dbname].$DbInfo2[prefix]Media (Name, Type, Size, StorageMethod, Path, InsertUserID, DateInserted, ForeignID, ForeignTable) SELECT Name, MimeType, Size, 'local', Path, UserID, DateCreated, DiscussionID, 'discussion' from $DbInfo1[dbname].$DbInfo1[prefix]Attachment WHERE $DbInfo1[dbname].$DbInfo1[prefix]attachment.AttachmentID IN(SELECT AttachmentID FROM $DbInfo1[dbname].$DbInfo1[prefix]attachment JOIN $DbInfo1[dbname].$DbInfo1[prefix]discussion ON $DbInfo1[dbname].$DbInfo1[prefix]attachment.DiscussionID = $DbInfo1[dbname].$DbInfo1[prefix]discussion.DiscussionID WHERE $DbInfo1[dbname].$DbInfo1[prefix]attachment.CommentID = $DbInfo1[dbname].$DbInfo1[prefix]discussion.FirstCommentID)"; | |
| } | |
| else { | |
| $queryOut1 = "SELECT Name, MimeType, Size, 'local', Path, UserID, DateCreated, CommentID, 'comment' from $DbInfo1[prefix]Attachment WHERE $DbInfo1[prefix]attachment.AttachmentID NOT IN(SELECT AttachmentID FROM $DbInfo1[prefix]attachment JOIN $DbInfo1[prefix]discussion ON $DbInfo1[prefix]attachment.DiscussionID = $DbInfo1[prefix]discussion.DiscussionID WHERE $DbInfo1[prefix]attachment.CommentID = $DbInfo1[prefix]discussion.FirstCommentID)"; | |
| $queryIn1 = "INSERT INTO $DbInfo2[prefix]Media (Name, Type, Size, StorageMethod, Path, InsertUserID, DateInserted, ForeignID, ForeignTable)"; | |
| $queryOut2 = "SELECT Name, MimeType, Size, 'local', Path, UserID, DateCreated, DiscussionID, 'discussion', DateCreated from $DbInfo1[prefix]Attachment WHERE $DbInfo1[prefix]attachment.AttachmentID IN(SELECT AttachmentID FROM $DbInfo1[prefix]attachment JOIN $DbInfo1[prefix]discussion ON $DbInfo1[prefix]attachment.DiscussionID = $DbInfo1[prefix]discussion.DiscussionID WHERE $DbInfo1[prefix]attachment.CommentID = $DbInfo1[prefix]discussion.FirstCommentID)"; | |
| $queryIn2 = "INSERT INTO $DbInfo2[prefix]Media (Name, Type, Size, StorageMethod, Path, InsertUserID, DateInserted, ForeignID, ForeignTable)"; | |
| } | |
| if ($this->UseSameTable || $this->UseSameDatabase){ | |
| $Connection = mysql_connect($this->DbInfo1['dbhost'], $this->DbInfo1['dbuser'], $this->DbInfo1['dbpass']); | |
| mysql_select_db($this->DbInfo1['dbname'], $Connection); | |
| $Result1 = mysql_query($query1, $Connection); | |
| if ($Result1 === FALSE) { | |
| trigger_error(mysql_error($Connection)); | |
| $Result1 = "Export failed on database issues - query1: " . $query1; | |
| } | |
| $Result2 = mysql_query($query2, $Connection); | |
| if ($Result2 === FALSE) { | |
| trigger_error(mysql_error($Connection)); | |
| $Result1 = "Export failed on database issues - query2: ". $query2; | |
| } | |
| if ($Result1 === FALSE || $Result2 === FALSE){ | |
| return $Result1 . $Result2; | |
| } | |
| else { | |
| return true; | |
| } | |
| } | |
| return true; | |
| } | |
| } | |
| // Instantiate the appropriate controller or display the input page. | |
| if(isset($_POST['submit'])) { | |
| // Mini-Factory | |
| $Controller = new DbHandling(); | |
| $Controller->DoExport(); | |
| } | |
| else { | |
| $CanWrite = TestWrite(); | |
| ViewForm(array('CanWrite' => $CanWrite)); | |
| } | |
| /** | |
| * Test filesystem permissions | |
| */ | |
| function TestWrite() { | |
| // Create file | |
| $file = 'vanilla2test.txt'; | |
| @touch($file); | |
| if(is_writable($file)) { | |
| @unlink($file); | |
| return true; | |
| } | |
| else return false; | |
| } | |
| <?php | |
| define('VERSION', '0.1'); | |
| /** | |
| * Vanilla Attachments to FileUpload Porter | |
| * This is not an official Vanilla Plugin, Layout was taken from Vanilla 2 Exporter | |
| * This script puts Vanilla1 Attachment files to Vanilla 2 FileUpload | |
| * see http://www.vanillaforums.org/discussion/13136/attachments-to-fileupload-importer for more information | |
| * The function of this script comes from user rayk. | |
| * brought to PHP and made more user friendly by user vegano | |
| */ | |
| /** | |
| * Debug Mode | |
| * set to true to see the values of the fifth file that should be copied | |
| */ | |
| $debug = true; | |
| /** | |
| * HTML header | |
| */ | |
| function PageHeader() { | |
| ?> | |
| <?xml version="1.0" encoding="UTF-8"?> | |
| <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> | |
| <html> | |
| <head> | |
| <title>Vanilla Attachments to FileUpload Porter - Form Vanilla1 to Vanilla2</title> | |
| <style> | |
| body { | |
| font-family: 'lucida grande','Lucida Sans Unicode', tahoma, sans-serif; | |
| background: url('http://vanillaforums.com/porter/slicesplash.jpg') top center no-repeat #C7E6FB; | |
| margin: 0px; | |
| padding: 0px; | |
| text-align: center; | |
| color:#076C8E; | |
| text-shadow:0 1px 0 #FFFFFF; | |
| } | |
| a, | |
| a:link, | |
| a:active, | |
| a:visited { | |
| color: #2786C2; | |
| text-decoration: none; | |
| } | |
| a:hover { | |
| color: #FF0084 !important; | |
| text-decoration: underline; | |
| } | |
| div.Title { | |
| background:#E2F4FF none repeat scroll 0 0; | |
| border-top: 1px solid #A5D0E7; | |
| border-bottom: 1px solid #A5D0E7; | |
| margin: 50px 0; | |
| padding: 30px 0 4px; | |
| } | |
| div.Title h1 { | |
| text-align: left; | |
| width: 600px; | |
| margin: 0 auto; | |
| } | |
| div.Title img { | |
| top: 20px; | |
| position: absolute; | |
| } | |
| div.Title p { | |
| padding: 0 0 0 270px; | |
| margin: 0; | |
| font-size: 30px; | |
| } | |
| h1 { | |
| font-family: Arial, Helvetica, Verdana; | |
| color: #02455B; | |
| width: 568px; | |
| margin: 0 auto; | |
| padding: 0; | |
| font-size: 180%; | |
| } | |
| div.Form { | |
| text-align: center; | |
| width: 900px; | |
| margin: 0 auto; | |
| adding: 0; | |
| } | |
| div.Form ul { | |
| width: 80%; | |
| margin: auto; | |
| } | |
| div.Errors { | |
| background: #d00; | |
| padding: 20px 8px !important; | |
| margin: 0 0 10px; | |
| border-bottom: 1px solid #C0E7F5; | |
| } | |
| .Errors li { | |
| padding: 4px 0 !important; | |
| border: 0px !important; | |
| margin: 0px !important; | |
| color: #fff !important; | |
| font-size: 16px; | |
| line-height: 150%; | |
| text-shadow: #900 0 1px 0; | |
| } | |
| .Errors li pre, | |
| .Errors li code { | |
| border-radius: 3px; | |
| -moz-border-radius: 3px; | |
| -webkit-border-radius: 3px; | |
| border: 1px solid #b00; | |
| background: #c00; | |
| margin: 10px 0 0; | |
| padding: 4px 8px; | |
| display: block; | |
| text-shadow: none; | |
| font-size: 13px; | |
| font-weight: normal; | |
| font-family: monospace; | |
| } | |
| .Errors li a { | |
| color: #ffff00; | |
| text-decoration: underline; | |
| } | |
| .Errors li a:hover { | |
| color: #ff0 !important; | |
| text-decoration: none; | |
| } | |
| .Hidden { | |
| display: none; | |
| } | |
| /* Forms */ | |
| form { | |
| margin: 0 0 20px; | |
| text-align: right; | |
| } | |
| form ul { | |
| text-align: left; | |
| list-style: none; | |
| margin: 0px; | |
| padding: 10px; | |
| } | |
| form ul li { | |
| padding: 10px 0; | |
| font-size: 18px; | |
| } | |
| form ul li.Warning { | |
| padding-bottom: 0; | |
| border-bottom: 0; | |
| font-size: 17px; | |
| } | |
| form ul li.Warning div { | |
| font-size: 14px; | |
| line-height: 1.6; | |
| color: #000; | |
| text-shadow: none; | |
| padding: 16px 0 8px; | |
| } | |
| form label { | |
| font-family: Arial, Helvetica, Verdana; | |
| font-weight: bold; | |
| display: block; | |
| padding: 8px 0 0; | |
| font-size: 110%; | |
| color: #02455B; | |
| } | |
| form label span { | |
| font-size: 13px; | |
| color: #555; | |
| font-weight: normal; | |
| text-shadow: none; | |
| padding: 0 0 0 10px; | |
| } | |
| form select { | |
| border-radius: 4px; | |
| -moz-border-radius: 4px; | |
| -webkit-border-radius: 4px; | |
| font-size: 110%; | |
| padding: 8px; | |
| width: 496px; | |
| border: 1px solid #ccc; | |
| color: #555; | |
| } | |
| form input.InputBox { | |
| border-radius: 4px; | |
| -moz-border-radius: 4px; | |
| -webkit-border-radius: 4px; | |
| font-size: 110%; | |
| padding: 8px; | |
| width: 420px; | |
| border: 1px solid #ccc; | |
| color: #555; | |
| } | |
| form input.InputBox:focus { | |
| color: #000; | |
| background: #FFFEDE; | |
| border: 1px solid #aaa; | |
| } | |
| form li.Last { | |
| padding: 12px 0 2px; | |
| border-bottom: 0; | |
| } | |
| div.Button { | |
| text-align: right; | |
| padding: 12px 0 30px; | |
| width: 496px; | |
| margin: 0 auto; | |
| clear: both; | |
| } | |
| div.Button a, | |
| input.Button { | |
| cursor: pointer; | |
| font-family: arial, helvetica, verdana; | |
| font-size: 25px; | |
| font-weight: bold; | |
| color: #02475A; | |
| text-shadow: 0 1px 0 #fff; | |
| margin: 0; | |
| padding: 3px 10px; | |
| background: url('http://vanillaforums.com/porter/buttonbg.png') repeat-x center left #f8f8f8; | |
| border: 1px solid #999; | |
| border-radius: 3px; | |
| -moz-border-radius: 3px; | |
| -webkit-border-radius: 3px; | |
| box-shadow: 0px 0px 2px #999; | |
| -moz-box-shadow: 0px 0px 2px #999; | |
| -webkit-box-shadow: 0px 0px 2px #999; | |
| } | |
| div.Button a { | |
| padding: 4px 8px; | |
| } | |
| div.Button a:hover, | |
| input.Button:hover { | |
| text-decoration: none; | |
| color: #111; | |
| border: 1px solid #666; | |
| } | |
| div.Button a:focus, | |
| input.Button:focus { | |
| background: #eee; | |
| } | |
| div.Attachments, div.FileUpload { | |
| width: 440px; | |
| } | |
| div.Attachments { | |
| float: left; | |
| } | |
| div.FileUpload { | |
| float: right; | |
| } | |
| /* readme.html */ | |
| div.Info { | |
| text-align: left; | |
| width: 568px; | |
| margin: 0 auto 0px; | |
| font-size: 80%; | |
| line-height: 1.6; | |
| } | |
| div.Info h1 { | |
| padding: 6px 0 0; | |
| margin: 0; | |
| } | |
| div.Info p { | |
| color: #000; | |
| padding: 3px 0 6px; | |
| margin: 0; | |
| text-shadow: none; | |
| } | |
| div.Info li { | |
| color: #000; | |
| padding: 1px 0; | |
| margin: 0; | |
| text-shadow: none; | |
| } | |
| code { | |
| font-size: 120%; | |
| font-family: Greorgia, Courier New, serif; | |
| } | |
| div.Code { | |
| background-color: #fff; | |
| border-radius: 4px; | |
| -moz-border-radius: 4px; | |
| -webkit-border-radius: 4px; | |
| padding: 8px; | |
| border: 1px solid #ccc; | |
| color: #555; | |
| } | |
| div.Report { | |
| font-size:70%; | |
| text-align: left; | |
| padding-left: 50px; | |
| } | |
| .Version { | |
| font-size: 9pt; | |
| font-weight: normal; | |
| } | |
| </style> | |
| <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script> | |
| <script type="text/javascript"> | |
| /* <![CDATA[ */ | |
| $(document).ready(function() { | |
| $("input[name='samedb']").change(function(){ | |
| if($(this).is(":checked")){ | |
| $(".FileUpload input[name='dbhost2'], .FileUpload input[name='dbuser2'], .FileUpload input[name='dbpass2']").css("background-color","ccc").attr("disabled", true); | |
| }else{ | |
| if($("input[name='sametable']").is(":checked")){ | |
| }else{ | |
| $(".FileUpload input[name='dbhost2'], .FileUpload input[name='dbuser2'], .FileUpload input[name='dbpass2']").css("background-color","#fff").attr("disabled", false); | |
| } } | |
| }); | |
| $("input[name='sametable']").change(function(){ | |
| if($(this).is(":checked")){ | |
| $(".FileUpload input[name='dbhost2'], .FileUpload input[name='dbuser2'], .FileUpload input[name='dbpass2'], .FileUpload input[name='dbname2']").css("background-color","ccc").attr("disabled", true); | |
| }else{ | |
| if($("input[name='samedb']").is(":checked")){ | |
| $(".FileUpload input[name='dbname2']").css("background-color","#fff").attr("disabled", false); | |
| }else{ | |
| $(".FileUpload input[name='dbhost2'], .FileUpload input[name='dbuser2'], .FileUpload input[name='dbpass2'], .FileUpload input[name='dbname2']").css("background-color","#fff").attr("disabled", false); | |
| }} | |
| }); | |
| if ($("input[name='samedb']").is(":checked")){ | |
| $(".FileUpload input[name='dbhost2'], .FileUpload input[name='dbuser2'], .FileUpload input[name='dbpass2']").css("background-color","ccc").attr("disabled", true); | |
| }; | |
| if ($("input[name='sametable']").is(":checked")){ | |
| $(".FileUpload input[name='dbhost2'], .FileUpload input[name='dbuser2'], .FileUpload input[name='dbpass2'], .FileUpload input[name='dbname2']").css("background-color","ccc").attr("disabled", true); | |
| }; | |
| }); | |
| /* ]]> */ | |
| </script> | |
| </head> | |
| <body> | |
| <div id="Frame"> | |
| <div id="Content"> | |
| <div class="Title"> | |
| <h1> | |
| <img src="http://vanillaforums.com/porter/vanilla_logo.png" alt="Vanilla" /> | |
| <p>Vanilla Attachments to FileUpload Porter - Form Vanilla1 to Vanilla2 <span class="Version">Version <?php echo VERSION; ?></span></p> | |
| </h1> | |
| </div> | |
| <?php | |
| } //PageHeader END | |
| /** | |
| * HTML footer | |
| */ | |
| function PageFooter() { | |
| ?> | |
| <div class="Thanks"> | |
| <p>Many thanks for the first step goes to user <strong>rayk</strong> and his friend who is doing Ruby</p> | |
| <p>The second step - bring it to PHP and make a little bit of GUI - was done by user <strong>vegano</strong></p> | |
| <p>check <a href="http://vanillaforums.org/discussion/13136/attachments-to-fileupload-importer">http://vanillaforums.org/discussion/13136/attachments-to-fileupload-importer</a> for more information.</p> | |
| </div> | |
| </div> | |
| </div> | |
| </body> | |
| </html> | |
| <?php | |
| } // PageFooter | |
| /** | |
| * Form: Database connection info | |
| */ | |
| function ViewForm($Data) { | |
| if ($debug == true) print_r($Data); | |
| echo $_POST['dbname1']; | |
| $msg = GetValue('Msg', $Data, ''); | |
| $Info = GetValue('Info', $Data, ''); | |
| $CanWrite = GetValue('CanWrite', $Data, NULL); | |
| if($CanWrite === NULL) | |
| $CanWrite = TestWrite(); | |
| PageHeader(); ?> | |
| <div class="Info"> | |
| Welcome to the Vanilla Attachments to FileUpload Porter. | |
| This application will export your existing Attachments of Vanilla 1 to FileUpload of Vanilla 2. <br />Please make sure the Plugin FileUpload is installed on a running installation of Vanilla 2. <br />You will have to know the login data of your database(s). May you have also to make some folders writeable. | |
| </div> | |
| <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> | |
| <input type="hidden" name="step" value="info" /> | |
| <div class="Form"> | |
| <?php if($msg!='') : ?> | |
| <div class="Messages Errors"> | |
| <ul> | |
| <li><?php echo $msg; ?></li> | |
| </ul> | |
| </div> | |
| <?php endif; ?> | |
| <div id="Vanilla1" class="Attachments"> | |
| <h3>Vanilla 1 - Attachments</h3> | |
| <ul> | |
| <li> | |
| <label>Van1 Table Prefix <span>Most installations have a database prefix, but if you're sure you don't have one you can leave this blank.</span></label> | |
| <input class="InputBox" type="text" name="prefix1" value="<?php echo urlencode(GetValue('prefix1','','lum_')) ?>" /> | |
| </li> | |
| <li> | |
| <label>Van1 Database Name <span>default of Attachments is "attachment"</span></label> | |
| <input class="InputBox" type="text" name="dbname1" value="<?php echo urlencode(GetValue('dbname1','','forum')) ?>" /> | |
| </li> | |
| <li> | |
| <label>Van1 Database Host <span>Database host is usually "localhost"</span></label> | |
| <input class="InputBox" type="text" name="dbhost1" value="<?php echo urlencode(GetValue('dbhost1', '', 'localhost')) ?>" /> | |
| </li> | |
| <li> | |
| <label>Van1 Database Username</label> | |
| <input class="InputBox" type="text" name="dbuser1" value="<?php echo urlencode(GetValue('dbuser1','','root')) ?>" /> | |
| </li> | |
| <li> | |
| <label>Van1 Database Password</label> | |
| <input class="InputBox" type="password" name="dbpass1" value="<?php echo GetValue('dbpass1') ?>" /> | |
| </li> | |
| <li> | |
| <label> | |
| <input class="CheckBox" type="checkbox" name="samedb" value="samedb" <?php if(GetValue('samedb')) echo 'checked="checked"'; ?> /> Same Database<span> vanilla1 and vanilla 2 share the same database </span></label> | |
| <label> | |
| <input class="CheckBox" type="checkbox" name="sametable" value="sametable" <?php if(GetValue('sametable')) echo 'checked="checked"'; ?> /> Same Table<span> vanilla1 and vanilla 2 share the same table </span> | |
| </label> | |
| </li> | |
| <li> | |
| <label>Attachment Directory Path <span>root directory of your Attachment plugin on Vanilla 1</span></label> | |
| <input class="InputBox" type="text" name="atpath" value="<?php echo GetValue('atpath') ?>" /> | |
| </li> | |
| </ul> | |
| </div> <!-- Vanilla1 End --> | |
| <div id="Vanilla2" class="FileUpload"> | |
| <h3>Vanilla 2 - FileUpload</h3> | |
| <ul> | |
| <li> | |
| <label>Van2 Table Prefix <span>Most installations have a database prefix, but if you're sure you don't have one you can leave this blank.</span></label> | |
| <input class="InputBox" type="text" name="prefix2" value="<?php echo urlencode(GetValue('prefix2','','gdn_')) ?>" /> | |
| </li> | |
| <li> | |
| <label>Van2 Database Name <span>default of FileUpload is "media"</span></label> | |
| <input class="InputBox" type="text" name="dbname2" value="<?php echo urlencode(GetValue('dbname2', '', 'forum2')) ?>" /> | |
| </li> | |
| <li> | |
| <label>Van2 Database Host <span>Database host is usually "localhost"</span></label> | |
| <input class="InputBox" type="text" name="dbhost2" value="<?php echo urlencode(GetValue('dbhost2', '', 'localhost')) ?>" /> | |
| </li> | |
| <li> | |
| <label>Van2 Database Username</label> | |
| <input class="InputBox" type="text" name="dbuser2" value="<?php echo urlencode(GetValue('dbuser2','','root')) ?>" /> | |
| </li> | |
| <li> | |
| <label>Van2 Database Password</label> | |
| <input class="InputBox" type="password" name="dbpass2" value="<?php echo GetValue('dbpass2') ?>" /> | |
| </li> | |
| <li> | |
| <label>FileUpload Directory Path <span>root directory of your FileUpload on Vanilla 2</span></label> | |
| <input class="InputBox" type="text" name="fupath" value="<?php echo GetValue('fupath') ?>" /> | |
| </li> | |
| <li> | |
| <label title="check FileUploads option 'Plugin.FileUpload.DispersionFactor' for more informations">FileUpload: Dispersion Factor <span>leave default (20) if you don't know what it is for.</span></label> | |
| <input class="InputBox" type="text" name="dispersion" value="<?php echo GetValue('dispersion', '',20) ?>" /> | |
| </li> | |
| </ul> | |
| </div> <!-- Vanilla2 End --> | |
| <div class="Button"> | |
| <label><input class="CheckBox" type="checkbox" id="testrun" name="testrun" value="testrun" <?php if(GetValue('testrun')) echo 'checked="checked"'; ?> /> Testrun <span>doesn't copy files</span></label> | |
| <label><input class="Button" type="submit" name="submit" value="Begin Export" /></label> | |
| </div> | |
| </div> | |
| </form> | |
| <?php PageFooter(); | |
| } // Database Connect Info END | |
| /** | |
| * Function: GetValue | |
| */ | |
| function GetValue($Key, $Collection = NULL, $Default = '') { | |
| if(!$Collection) | |
| $Collection = $_POST; | |
| if(array_key_exists($Key, $Collection)) | |
| return $Collection[$Key]; | |
| return $Default; | |
| } // Get Value End | |
| /** Export the Attachments Database Entries to FileUpload Database */ | |
| class DbHandling { | |
| /** @var array Database Van1 connection info */ | |
| protected $DbInfo1 = array(); | |
| /** @var array Database Van2 connection info */ | |
| protected $DbInfo2 = array(); | |
| /** @var array File path info */ | |
| protected $FileInfo = array(); | |
| protected $IsTestrun = FALSE; | |
| protected $UseSameDatabase = FALSE; | |
| protected $UseSameTable = FALSE; | |
| /** | |
| * Construct and set the controller's properties from the posted form. | |
| */ | |
| public function __construct() { | |
| $this->HandleInfoForm(); | |
| } | |
| /** | |
| * User submitted db connection info | |
| */ | |
| public function HandleInfoForm() { | |
| $this->IsTestrun = array_key_exists('testrun', $_POST) ? TRUE : FALSE; // Is Testrun? | |
| $this->UseSameDatabase = (array_key_exists('samedb', $_POST) || ($_POST['dbuser1'] == $_POST['dbuser2'] && $_POST['dbhost1'] == $_POST['dbhost2'] && $_POST['dbpass1'] == $_POST['dbpass2'])) ? TRUE : FALSE; // Attachments and FileUpload have same Database? | |
| $this->UseSameTable = (array_key_exists('sametable', $_POST) || ($_POST['dbuser1'] == $_POST['dbuser2'] && $_POST['dbhost1'] == $_POST['dbhost2'] && $_POST['dbpass1'] == $_POST['dbpass2'] && $_POST['dbname1'] == $_POST['dbname2'])) ? TRUE : FALSE; // Attachments and FileUpload have same Table? | |
| $this->DispersionFactor = array_key_exists('dispersion', $_POST) ? $_POST['dispersion'] : 20; | |
| // Attachments Database | |
| $this->DbInfo1 = array( | |
| 'app' => 'Vanilla 1', | |
| 'dbhost' => $_POST['dbhost1'], | |
| 'dbuser' => $_POST['dbuser1'], | |
| 'dbpass' => $_POST['dbpass1'], | |
| 'dbname' => $_POST['dbname1'], | |
| 'table' => 'attachment', | |
| 'prefix' => preg_replace('/[^A-Za-z0-9_-]/','',$_POST['prefix1'])); | |
| if($this->UseSameTable || $this->UseSameDatabase) { | |
| $_POST['dbhost2'] = $_POST['dbhost1']; | |
| $_POST['dbuser2'] = $_POST['dbuser1']; | |
| $_POST['dbpass2'] = $_POST['dbpass1']; | |
| if($this->UseSameTable) $_POST['dbname2'] = $_POST['dbname1']; | |
| } | |
| // FileUpload Database | |
| $this->DbInfo2 = array( | |
| 'app' => 'Vanilla 2', | |
| 'dbhost' => $_POST['dbhost2'], | |
| 'dbuser' => $_POST['dbuser2'], | |
| 'dbpass' => $_POST['dbpass2'], | |
| 'dbname' => $_POST['dbname2'], | |
| 'table' => 'media', | |
| 'prefix' => preg_replace('/[^A-Za-z0-9_-]/','',$_POST['prefix2'])); | |
| $this->FileInfo = array( | |
| 'attachment' => $_POST['atpath'], | |
| 'fileupload' => $_POST['fupath'] | |
| ); | |
| } | |
| /** | |
| * Test database connection info | |
| */ | |
| public function TestDatabase($DbInfo) { | |
| // Connection | |
| if($C = @mysql_connect($DbInfo['dbhost'], $DbInfo['dbuser'], $DbInfo['dbpass'])) { | |
| // Check for Database | |
| if(mysql_select_db($DbInfo['dbname'], $C)) { | |
| // Check for attachment/media table | |
| $return = mysql_list_tables($DbInfo['dbname']); | |
| while ($row = mysql_fetch_row($return)) { | |
| $tables[] = $row[0]; | |
| } | |
| if (in_array($DbInfo['prefix'].$DbInfo['table'], $tables)) {mysql_close($C); | |
| return true; | |
| } | |
| else { | |
| mysql_close($C); | |
| return $DbInfo['app'] . ' database failure: Could not find table “'.$DbInfo['prefix'].$DbInfo['table'].'”. '; | |
| } | |
| } | |
| else { | |
| mysql_close($C); | |
| return $DbInfo['app'] . ' database failure: Could not find database “'.$DbInfo['dbname'].'”. '; | |
| } | |
| } | |
| else | |
| return $DbInfo['app'] . ' database failure: Could not connect to host “'.$DbInfo['dbhost'].'” as user “'.$DbInfo['dbuser'].'” with given password. '; | |
| } | |
| /** | |
| * Test file write permissions info | |
| */ | |
| public function TestFilePermission($FileInfo) { | |
| $return = ''; | |
| if(!is_readable($FileInfo['attachment'])) $return .= 'file permission error: Could not read for attachment directory at: ' . $FileInfo['attachment'] . '<br />'; | |
| if(!is_writable($FileInfo['fileupload'])) $return .= 'file permission error: Could not write to attachment directory at: ' . $FileInfo['fileupload'] . '<br />'; | |
| if ($return != '') return $return; | |
| return true; | |
| } | |
| public function DoExport() { | |
| // Test connection | |
| $Msg = $this->TestDatabase($this->DbInfo1); | |
| $Msg = ($Msg === true) ? $this->TestDatabase($this->DbInfo2) : $Msg . "<br />" . $this->TestDatabase($this->DbInfo2); | |
| $Msg = ($Msg === true) ? $this->TestFilePermission($this->FileInfo) : $Msg. "<br />" . $this->TestFilePermission($this->FileInfo); | |
| if($Msg === true) { | |
| // Test src tables' existence structure | |
| $Msg = $this->ExecuteQuery($this->DbInfo1, $this->DbInfo2); | |
| if ($Msg === true) { | |
| ViewForm(array('Msg' => 'Database transfere passed but file transfer not yet implemented in this script!', 'Info' => $this->DbInfo1)); // Back to form with gratulation | |
| /* $Msg = $this->ExecuteFiletransfer($this->FileInfo, $this->DbInfo2); | |
| if ($Msg === true) { | |
| ViewCongratulations(); | |
| } | |
| else { | |
| ViewForm(array('Msg' => $Msg, 'Info' => $this->DbInfo1)); // Back to form with error | |
| } | |
| */ | |
| } | |
| else { | |
| ViewForm(array('Msg' => $Msg, 'Info' => $this->DbInfo1)); // Back to form with error | |
| } | |
| } | |
| else { | |
| ViewForm(array('Msg' => $Msg, 'Info' => $this->DbInfo1)); // Back to form with error | |
| } | |
| } | |
| public function ExecuteQuery($DbInfo1, $DbInfo2) { | |
| if ($this->UseSameTable){ | |
| $query1 = "INSERT INTO $DbInfo2[prefix]Media (Name, Type, Size, StorageMethod, Path, InsertUserID, DateInserted, ForeignID, ForeignTable) SELECT Name, MimeType, Size, 'local', Path, UserID, DateCreated, CommentID, 'comment' from $DbInfo1[prefix]Attachment WHERE $DbInfo1[prefix]attachment.AttachmentID NOT IN(SELECT AttachmentID FROM $DbInfo1[prefix]attachment JOIN $DbInfo1[prefix]discussion ON $DbInfo1[prefix]attachment.DiscussionID = $DbInfo1[prefix]discussion.DiscussionID WHERE $DbInfo1[prefix]attachment.CommentID = $DbInfo1[prefix]discussion.FirstCommentID)"; | |
| $query2 = "INSERT INTO $DbInfo2[prefix]Media (Name, Type, Size, StorageMethod, Path, InsertUserID, DateInserted, ForeignID, ForeignTable) SELECT Name, MimeType, Size, 'local', Path, UserID, DateCreated, DiscussionID, 'discussion' from $DbInfo1[prefix]Attachment WHERE $DbInfo1[prefix]attachment.AttachmentID IN(SELECT AttachmentID FROM $DbInfo1[prefix]attachment JOIN $DbInfo1[prefix]discussion ON $DbInfo1[prefix]attachment.DiscussionID = $DbInfo1[prefix]discussion.DiscussionID WHERE $DbInfo1[prefix]attachment.CommentID = $DbInfo1[prefix]discussion.FirstCommentID)"; | |
| } | |
| elseif (!$this->UseSameTable && $this->UseSameDatabase) { | |
| $query1 = "INSERT INTO $DbInfo2[dbname].$DbInfo2[prefix]Media (Name, Type, Size, StorageMethod, Path, InsertUserID, DateInserted, ForeignID, ForeignTable) SELECT Name, MimeType, Size, 'local', Path, UserID, DateCreated, CommentID, 'comment' from $DbInfo1[dbname].$DbInfo1[prefix]Attachment WHERE $DbInfo1[dbname].$DbInfo1[prefix]attachment.AttachmentID NOT IN(SELECT AttachmentID FROM $DbInfo1[dbname].$DbInfo1[prefix]attachment JOIN $DbInfo1[dbname].$DbInfo1[prefix]discussion ON $DbInfo1[dbname].$DbInfo1[prefix]attachment.DiscussionID = $DbInfo1[dbname].$DbInfo1[prefix]discussion.DiscussionID WHERE $DbInfo1[dbname].$DbInfo1[prefix]attachment.CommentID = $DbInfo1[dbname].$DbInfo1[prefix]discussion.FirstCommentID)"; | |
| $query2 = "INSERT INTO $DbInfo2[dbname].$DbInfo2[prefix]Media (Name, Type, Size, StorageMethod, Path, InsertUserID, DateInserted, ForeignID, ForeignTable) SELECT Name, MimeType, Size, 'local', Path, UserID, DateCreated, DiscussionID, 'discussion' from $DbInfo1[dbname].$DbInfo1[prefix]Attachment WHERE $DbInfo1[dbname].$DbInfo1[prefix]attachment.AttachmentID IN(SELECT AttachmentID FROM $DbInfo1[dbname].$DbInfo1[prefix]attachment JOIN $DbInfo1[dbname].$DbInfo1[prefix]discussion ON $DbInfo1[dbname].$DbInfo1[prefix]attachment.DiscussionID = $DbInfo1[dbname].$DbInfo1[prefix]discussion.DiscussionID WHERE $DbInfo1[dbname].$DbInfo1[prefix]attachment.CommentID = $DbInfo1[dbname].$DbInfo1[prefix]discussion.FirstCommentID)"; | |
| } | |
| else { | |
| $queryOut1 = "SELECT Name, MimeType, Size, 'local', Path, UserID, DateCreated, CommentID, 'comment' from $DbInfo1[prefix]Attachment WHERE $DbInfo1[prefix]attachment.AttachmentID NOT IN(SELECT AttachmentID FROM $DbInfo1[prefix]attachment JOIN $DbInfo1[prefix]discussion ON $DbInfo1[prefix]attachment.DiscussionID = $DbInfo1[prefix]discussion.DiscussionID WHERE $DbInfo1[prefix]attachment.CommentID = $DbInfo1[prefix]discussion.FirstCommentID)"; | |
| $queryIn1 = "INSERT INTO $DbInfo2[prefix]Media (Name, Type, Size, StorageMethod, Path, InsertUserID, DateInserted, ForeignID, ForeignTable)"; | |
| $queryOut2 = "SELECT Name, MimeType, Size, 'local', Path, UserID, DateCreated, DiscussionID, 'discussion', DateCreated from $DbInfo1[prefix]Attachment WHERE $DbInfo1[prefix]attachment.AttachmentID IN(SELECT AttachmentID FROM $DbInfo1[prefix]attachment JOIN $DbInfo1[prefix]discussion ON $DbInfo1[prefix]attachment.DiscussionID = $DbInfo1[prefix]discussion.DiscussionID WHERE $DbInfo1[prefix]attachment.CommentID = $DbInfo1[prefix]discussion.FirstCommentID)"; | |
| $queryIn2 = "INSERT INTO $DbInfo2[prefix]Media (Name, Type, Size, StorageMethod, Path, InsertUserID, DateInserted, ForeignID, ForeignTable)"; | |
| } | |
| if ($this->IsTestrun) return "Testrun, so no database action executed - this queries would be executed:<br />" . $query1 . "<br />" . $query2; | |
| if ($this->UseSameTable || $this->UseSameDatabase){ | |
| $Connection = mysql_connect($this->DbInfo1['dbhost'], $this->DbInfo1['dbuser'], $this->DbInfo1['dbpass']); | |
| mysql_select_db($this->DbInfo1['dbname'], $Connection); | |
| $Result1 = mysql_query($query1, $Connection); | |
| if ($Result1 === FALSE) { | |
| trigger_error(mysql_error($Connection)); | |
| $Result1 = "Export failed on database issues - query1: " . $query1; | |
| } | |
| $Result2 = mysql_query($query2, $Connection); | |
| if ($Result2 === FALSE) { | |
| trigger_error(mysql_error($Connection)); | |
| $Result1 = "Export failed on database issues - query2: ". $query2; | |
| } | |
| if ($Result1 === FALSE || $Result2 === FALSE){ | |
| return $Result1 . $Result2; | |
| } | |
| else { | |
| return true; | |
| } | |
| } | |
| return true; | |
| } | |
| } | |
| // Instantiate the appropriate controller or display the input page. | |
| if(isset($_POST['submit'])) { | |
| // Mini-Factory | |
| $Controller = new DbHandling(); | |
| $Controller->DoExport(); | |
| } | |
| else { | |
| $CanWrite = TestWrite(); | |
| ViewForm(array('CanWrite' => $CanWrite)); | |
| } | |
| /** | |
| * Test filesystem permissions | |
| */ | |
| function TestWrite() { | |
| // Create file | |
| $file = 'vanilla2test.txt'; | |
| @touch($file); | |
| if(is_writable($file)) { | |
| @unlink($file); | |
| return true; | |
| } | |
| else return false; | |
| } | |
correct the SQL request, need to check wheter a post ist the FirstComment of a Discussion
INSERT INTO forum2.GDN_Media (Name, Type, Size, StorageMethod, Path, InsertUserID, DateInserted, ForeignID, ForeignTable) SELECT Name, MimeType, Size, 'local', Path, UserID, DateCreated, CommentID, 'comment' from forum.LUM_Attachment WHERE forum.lum_attachment.AttachmentID NOT IN(SELECT AttachmentID FROM forum.lum_attachment JOIN forum.lum_discussion ON forum.lum_attachment.DiscussionID = forum.lum_discussion.DiscussionID WHERE forum.lum_attachment.CommentID = forum.lum_discussion.FirstCommentID)
INSERT INTO forum2.GDN_Media (Name, Type, Size, StorageMethod, Path, InsertUserID, DateInserted, ForeignID, ForeignTable) SELECT Name, MimeType, Size, 'local', Path, UserID, DateCreated, DiscussionID, 'discussion', DateCreated from forum.LUM_Attachment WHERE forum.lum_attachment.AttachmentID IN(SELECT AttachmentID FROM forum.lum_attachment JOIN forum.lum_discussion ON forum.lum_attachment.DiscussionID = forum.lum_discussion.DiscussionID WHERE forum.lum_attachment.CommentID = forum.lum_discussion.FirstCommentID)
just notes:
INSERT INTO GDN_Media (Name, Type, Size,
StorageMethod, Path, InsertUserID, ForeignID,
ForeignTable) SELECT Name, MimeType, Size, 'local',
Path, UserID, CommentID, 'comment' from
LUM_Attachment
$sql = "SELECT Name, MimeType, Size, 'local',
Path, UserID, CommentID, 'comment' FROM
lum_attachment";SELECT Name, MimeType, Size, 'local', Path, UserID,
CommentID, 'comment'
FROM
lum_attachmentD:/xampplite/htdocs/forum/attachments.csv
D:/xampplite/htdocs/forum/uploads/Attachments/
D:/xampplite/htdocs/forum2/uploads/FileUpload
Plugin.FileUpload.DispersionFactor