Last active
December 27, 2016 18:38
-
-
Save Rachind/08f5946392614bc624457e81c468ed86 to your computer and use it in GitHub Desktop.
MODX Convert Evogallery to Gallery
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* config */ | |
$db_host = 'localhost'; | |
$db_user = ''; | |
$db_pass = ''; | |
$db_name = ''; | |
$tv_gallery_id = 82; | |
/* end config */ | |
if (!mysql_connect($db_host, $db_user, $db_pass)) { | |
echo "MySQL error"; | |
exit; | |
} | |
mysql_select_db($db_name); | |
$result = array(); | |
mysql_set_charset( 'utf8' ); | |
$query = mysql_query("SELECT content_id | |
FROM `modx_portfolio_galleries` | |
GROUP BY `content_id` "); | |
mysql_set_charset( 'cp1251' ); | |
while($row = mysql_fetch_assoc($query)){ | |
$q = mysql_query("SELECT pagetitle FROM `modx_site_content` WHERE id='".$row['content_id']."' LIMIT 1"); | |
$r = mysql_fetch_assoc($q); | |
$pagetitle = $r['pagetitle']; | |
if($pagetitle == ''){ | |
$pagetitle = 'Gallery '.$row['content_id']; | |
} | |
$result[] = array( | |
'content_id'=>$row['content_id'], | |
'pagetitle'=>$pagetitle, | |
); | |
} | |
foreach($result as $item){ | |
$q = mysql_query("SELECT id FROM `modx_site_tmplvar_contentvalues` WHERE contentid='".$item['content_id']."' LIMIT 1"); | |
$r = mysql_fetch_assoc($q); | |
if(isset($r['id'])){ | |
mysql_query("INSERT INTO `modx_site_tmplvar_contentvalues` SET tmplvarid = '".$tv_gallery_id."', contentid='".$item['content_id']."', value = '".$item['content_id']."'"); | |
} | |
mysql_query("INSERT INTO `modx_gallery_albums` | |
(`id`, `parent`, `name`, `year`, `description`, `createdon`, `createdby`, `rank`, `active`, `prominent`, `watermark`, `cover_filename`) | |
VALUES | |
(".$item['content_id'].", 0, '".$item['pagetitle']."', '', '', '2016-12-27 21:36:32', 1, 0, 1, 1, '', '')"); | |
} | |
mysql_set_charset( 'utf8' ); | |
$query = mysql_query("SELECT * | |
FROM `modx_portfolio_galleries` | |
"); | |
//mysql_set_charset( 'cp1251' ); | |
while($row = mysql_fetch_assoc($query)){ | |
mysql_query( | |
"INSERT INTO `modx_gallery_items` | |
(`name`, `filename`, `description`, `mediatype`, `url`, `createdon`, `createdby`, `active`, `duration`, `streamer`, `watermark_pos`) | |
VALUES | |
('".$row['filename']."', '".$row['content_id']."/".$row['filename']."', '".$row['title']."', 'image', NULL, '2016-12-27 21:36:32', 1, 1, '', NULL, 'tl')"); | |
mysql_query("INSERT INTO `modx_gallery_album_items` (`item`, `album`, `rank`) VALUES (".mysql_insert_id().", ".$row['content_id'].", 1)"); | |
} | |
echo 'Ok'; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment