<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Sukria.net &#187; Wordpress</title>
	<atom:link href="http://www.sukria.net/fr/archives/tag/wordpress/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.sukria.net/fr</link>
	<description>I will press many keys on my keyboard causing an implementation to occur.</description>
	<lastBuildDate>Wed, 18 Jan 2012 17:11:38 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Migrating homebrew Rails blog-entries to WordPress with Perl</title>
		<link>http://www.sukria.net/fr/archives/2009/12/24/migrating-homebrew-rails-blog-entries-to-wordpress-with-perl/</link>
		<comments>http://www.sukria.net/fr/archives/2009/12/24/migrating-homebrew-rails-blog-entries-to-wordpress-with-perl/#comments</comments>
		<pubDate>Thu, 24 Dec 2009 11:33:19 +0000</pubDate>
		<dc:creator>sukria</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Coat::Persistent]]></category>
		<category><![CDATA[Migrating]]></category>
		<category><![CDATA[Perl]]></category>
		<category><![CDATA[Wordpress]]></category>

		<guid isPermaLink="false">http://www.sukria.net/fr/?p=1361</guid>
		<description><![CDATA[I was facing a challenge recently at work: migrating a bunch of blog entries stored in a Postgres database of a home-made Rails application to a WordPress blog. This challenge was trickier than you may first think because of the following reasons: I don&#8217;t have manual access to the Postgres DB, I can only run &#8230; <a href="http://www.sukria.net/fr/archives/2009/12/24/migrating-homebrew-rails-blog-entries-to-wordpress-with-perl/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I was facing a challenge recently at work: migrating a bunch of blog entries stored in a Postgres database of a home-made Rails application to a WordPress blog.</p>
<p>This challenge was trickier than you may first think because of the following reasons:</p>
<ol>
<li>I don&#8217;t have manual access to the Postgres DB, I can only run a Rails console that connects to it</li>
<li>The Postgres DB and the WordPress Blog are installed on two different servers that are not in the same LAN.</li>
</ol>
<p>Here is how I did the job, of course, using Perl as my weapon was the only option I considered, and I&#8217;m glad of it.</p>
<h2>First step : exporting the data, JSON FTW</h2>
<p>As the only way I had to handle the data source was a Rails console, I chose first to use YAML for exporting the data into a file, but I wasn&#8217;t able to parse it with Perl then, because of badly-written multiline scalars (I don&#8217;t know whose fault it is, either Ruby or Perl YAML modules, but it didn&#8217;t work out of the box).</p>
<p>Then I tried JSON:</p>
<pre class="prettyprint">
# dump_posts.rb (to be run with ./script/runner -e production)
posts = MyRailsPost.find(:all)
f = File.new("/tmp/posts.json", 'w')
f.write(posts.to_json)
f.close
</pre>
<p>I then uploaded the json file to my second server, where I have access to the WordPress DB and started writing an importer.</p>
<h2>From a JSON file to a WordPress DB</h2>
<p>Now I have my data in JSON format, I can write a Perl script that will parse it and insert each post item found in the WordPress &#8220;wp_posts&#8221; table. </p>
<p>First, I&#8217;ll write a Coat::Persistent class to handle WordPress blog posts:</p>
<pre class="prettyprint">
package WPPost;
use Coat;
use Coat::Persistent
    table_name => "wp_posts",
    primary_key => "ID";

has_p post_author => (isa => 'Int', required => 1);
has_p post_date => (isa => 'DateTime', coerce => 1);
has_p post_excerpt => (isa => 'Str');
has_p post_content => (isa => 'Str');
has_p post_title => (isa => 'Str');
has_p post_name => (isa => 'Str');

sub BUILD {
    my $self = shift;
    my $class = ref($self);
    $class->dbh->do('SET NAMES utf8') or die $!;
}

Coat::Persistent->disable_internal_sequence_engine();
__PACKAGE__->map_to_dbi(mysql => "MYDATABASE", "DBUSER", "DBPASS")
</pre>
<p>Please note that we tells DBD::mysql to send data in utf8 (SET NAMES utf8), this is very important, if we don&#8217;t, we&#8217;ll endup in WordPress with a mess of utf8/latin1 crap.</p>
<p>The post_date field will be set with Rails&#8217; created_at attribute, and it might be in a different format than YYYY-MM-DD HH:MM:SS, so I&#8217;ll write subtypes and coercions to handle that cleanly:</p>
<pre class="prettyprint">
use Coat::Types;
use Coat::Persistent::Types;

subtype 'DateTimeSec'
    => as 'Str'
    => where { /\d{4}-\d\d-\d\d \d+:\d+:\d+\.\d+/ };

subtype 'DateTimeWithTZ'
    => as 'Str'
    => where { /\d{4}-\d\d-\d\dT\d\d:\d\d:\d\d\+\d\d:\d\d/ };

subtype 'DateTimeWithT'
    => as 'Str'
    => where { /\d{4}-\d\d-\d\dT\d\d:\d\d:\d\d/ };

coerce 'DateTime'
    => from 'DateTimeWithTZ'
    => where { s/\+.+$//; s/T/ /; return $_ };

coerce 'DateTime'
    => from 'DateTimeWithT'
    => via { s/T/ /; return $_ };

coerce 'DateTime'
    => from 'DateTimeSec'
    => via { s/\.\d+$//; return $_ };
</pre>
<p>Now, I have all I need, I can write the scrit:</p>
<pre class="prettyprint">
#!/usr/bin/perl
use strict;
use warnings;

# slurping my JSON file
open FIC, '< ', $ARGV[0] or die $!;
my @lines = <FIC>;
close FIC;
my $content = join '', @lines;

# processing posts
my $data = from_json($content);
for my $post (@$data) {

    my $p = $post->{rails_post_class}; # JSON output in Rails works this way

    my $wp = WPPost->create(
        post_author => 1,               # admin
        post_date => $p->{created_at},  # coercion will occur here
        post_excerpt => $p->{excerpt},
        post_content => $p->{body},
        post_title => $p->{title},
        post_name => $p->{permalink},
    );
    print "+ ".$wp->post_title." -> #".$wp->ID."\n";
}
</pre>
<p>Note: you can consider this post as the first-and-last item of my 2009 Perl Advent Calendar ;)</p>
<div id='teoShare' ><div id='teo2Google'>
		<!-- Place this tag where you want the +1 button to render -->
		<g:plusone size='tall' annotation='none'></g:plusone>

		<!-- Place this render call where appropriate -->
		<script type='text/javascript'>
		  (function() {
			var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true;
			po.src = 'https://apis.google.com/js/plusone.js';
			var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s);
		  })();
		</script>
		</div><div id="teoTweet" >
		<a href="http://twitter.com/share" class="twitter-share-button" data-count="none" data-via="sukria">Tweet</a><script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script> </div></div><div style="height:0px; width:0px; overflow:hidden;"><a href="http://www.zeitblog.com/?in=plugin">blog tools and plugins from www.zeitblog.com</a></div><p>Related posts:<ol>
<li><a href='http://www.sukria.net/fr/archives/2009/11/14/coat-is-alive-sort-of/' rel='bookmark' title='Coat is alive (sort of)'>Coat is alive (sort of)</a> <small>Coat is a module I wrote when I needed Moose...</small></li>
<li><a href='http://www.sukria.net/fr/archives/2011/03/04/how-to-identify-a-good-perl-programmer-part-2/' rel='bookmark' title='How to Identify a Good Perl Programmer, part 2'>How to Identify a Good Perl Programmer, part 2</a> <small>Superman by Dunechaser Chromatic has published a set of questions...</small></li>
<li><a href='http://www.sukria.net/fr/archives/2010/07/01/perl-dancer-meeting-1/' rel='bookmark' title='Perl Dancer meeting #1'>Perl Dancer meeting #1</a> <small>As explained on the mailing list, we had the idea...</small></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.sukria.net/fr/archives/2009/12/24/migrating-homebrew-rails-blog-entries-to-wordpress-with-perl/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Weekly Random Links : Security</title>
		<link>http://www.sukria.net/fr/archives/2009/09/07/weekly-random-links-security/</link>
		<comments>http://www.sukria.net/fr/archives/2009/09/07/weekly-random-links-security/#comments</comments>
		<pubDate>Sun, 06 Sep 2009 23:07:47 +0000</pubDate>
		<dc:creator>sukria</dc:creator>
				<category><![CDATA[Mozilla]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[Wordpress]]></category>

		<guid isPermaLink="false">http://www.sukria.net/fr/?p=1203</guid>
		<description><![CDATA[Dear lazy web, this is my first attempt at publishing a selection of links I&#8217;ve recently bookmarked. Those links came to my attention mostly thanks to my twitter account. I&#8217;ll try to publish such a list every week (on sundays). Feel free to suggest me links either via Twitter or through this blog (comments are &#8230; <a href="http://www.sukria.net/fr/archives/2009/09/07/weekly-random-links-security/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Dear lazy web, this is my first attempt at publishing a selection of links I&#8217;ve recently bookmarked. Those links came to my attention mostly thanks to my <a href="http://twitter.com/sukria">twitter account</a>. I&#8217;ll try to publish such a list every week (on sundays). Feel free to suggest me links either via Twitter or through this blog (comments are welcome).</p>
<p>If a topic emerges from all the links I&#8217;ve bookmarked, I&#8217;ll put it in the title of the post, like you can see, this week, the trend topic is &#8220;Security&#8221;.</p>
<p>So here we go, happy links and if I give no news until then, have a good week.</p>
<ol>
<li>
<h4><a href="http://www.informationweek.com/blog/main/archives/2009/09/old_wordpress_s.html;jsessionid=2NRW0GOBKAJ5FQE1GHOSKHWATMY32JVN?cid=RSSfeed_IWK_ALL">Old WordPress Sites Exploited And Security Questioned</a></h4>
<p>Apparently this weekend, a major exploit attack has been taking place on old versions of self-hosted blogging platform WordPress. If you are using WordPress for your blog, you should update immediately.</p>
</li>
<li>
<h4><a href="http://friendfeed.com/scobleizer/cd43c6c3/i-dont-feel-safe-with-wordpress-hackers-broke-in">I don’t feel safe with WordPress, hackers &#8230;</a></h4>
<p>Once his blog has been exploited, a wordpress user doesn&#8217;t feel safe anymore. A discussion takes place in Friendfeed between him, Matt Mullenweg (WordPress author) and others&#8230;</p>
</li>
<li>
<h4><a href="http://wordpress.org/development/2009/09/keep-wordpress-secure/">How to Keep WordPress Secure</a></h4>
<p>Matt Mullenweg &#8211; WordPress author &#8211; writes some advices to keep your WordPress blog safe from exploits. <em>&#8220;Upgrading is taking your vitamins; fixing a hack is open heart surgery.&#8221;</em> he says.</p>
</li>
<li>
<h4><a href="http://www.smashingmagazine.com/2009/09/06/how-to-be-a-samurai-designer/">How To Be A Samurai Designer</a></h4>
<p>What if designing a web site was like a Samurai fight? Then Samurai&#8217;s good practices should apply to web designers: <em>“Matters of great concern should be treated lightly. Matters of small concern should be treated seriously.”</em>
</li>
<li>
<h4><a href="http://ardchoille42.blogspot.com/2009/09/about-capslock-key.html">About The Capslock Key</a></h4>
<p>The Capslock key : an appropriate demotivator</li>
<li>
<h4><a href="http://tech.slashdot.org/story/09/09/05/1157222/Mozilla-To-Protect-Adobe-Flash-Users?from=rss">Mozilla To Protect Adobe Flash Users</a></h4>
<p>Mozilla is going to check the version of installed Adobe Flash plug-ins and warn users if it discovers an outdated version with potential security holes. [...] Just recently, a study confirmed that 80 per cent of users surf with a vulnerable version of Adobe&#8217;s plug-in.&#8221;</li>
</ol>
<div id='teoShare' ><div id='teo2Google'>
		<!-- Place this tag where you want the +1 button to render -->
		<g:plusone size='tall' annotation='none'></g:plusone>

		<!-- Place this render call where appropriate -->
		<script type='text/javascript'>
		  (function() {
			var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true;
			po.src = 'https://apis.google.com/js/plusone.js';
			var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s);
		  })();
		</script>
		</div><div id="teoTweet" >
		<a href="http://twitter.com/share" class="twitter-share-button" data-count="none" data-via="sukria">Tweet</a><script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script> </div></div><div style="height:0px; width:0px; overflow:hidden;"><a href="http://www.zeitblog.com/?in=plugin">blog tools and plugins from www.zeitblog.com</a></div><p>No related posts.</p>]]></content:encoded>
			<wfw:commentRss>http://www.sukria.net/fr/archives/2009/09/07/weekly-random-links-security/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Nouvelle version du plugin WordPress pour Yoolink</title>
		<link>http://www.sukria.net/fr/archives/2008/12/23/nouvelle-version-du-plugin-wordpress-pour-yoolink/</link>
		<comments>http://www.sukria.net/fr/archives/2008/12/23/nouvelle-version-du-plugin-wordpress-pour-yoolink/#comments</comments>
		<pubDate>Tue, 23 Dec 2008 17:10:49 +0000</pubDate>
		<dc:creator>sukria</dc:creator>
				<category><![CDATA[Internet]]></category>
		<category><![CDATA[Plugin]]></category>
		<category><![CDATA[Wordpress]]></category>
		<category><![CDATA[yoolink]]></category>

		<guid isPermaLink="false">http://www.sukria.net/fr/?p=897</guid>
		<description><![CDATA[Une mise à jour du plugin WordPress est disponible depuis peu sur Yoolink. Cette version propose une nouvelle option concernant le flux RSS du blog : vous pouvez désormais choisir si vous voulez un lien &#8220;Ajouter sur Yoolink&#8221; dans votre flux RSS ou non. Au passage, l&#8217;ajout de cette option corrige un bug qui était &#8230; <a href="http://www.sukria.net/fr/archives/2008/12/23/nouvelle-version-du-plugin-wordpress-pour-yoolink/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Une mise à jour du plugin WordPress est <a href="http://www.yoolink.fr/webmaster">disponible depuis peu sur Yoolink</a>. </p>
<p>Cette version propose une nouvelle option concernant le flux RSS du blog : vous pouvez désormais choisir si vous voulez un lien &#8220;Ajouter sur Yoolink&#8221; dans votre flux RSS ou non.</p>
<p>Au passage, l&#8217;ajout de cette option corrige un bug qui était présent dans la version 1.0 du plugin, par rapport justement aux flux RSS.</p>
<p>Si vous avez installé la version 1.0 du plugin Yoolink Tools, je vous invite donc à effectuer <a href="http://www.yoolink.fr/download/yoolink-tools-for-wordpress.zip">la mise à jour</a> sans attendre.</p>
<div id='teoShare' ><div id='teo2Google'>
		<!-- Place this tag where you want the +1 button to render -->
		<g:plusone size='tall' annotation='none'></g:plusone>

		<!-- Place this render call where appropriate -->
		<script type='text/javascript'>
		  (function() {
			var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true;
			po.src = 'https://apis.google.com/js/plusone.js';
			var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s);
		  })();
		</script>
		</div><div id="teoTweet" >
		<a href="http://twitter.com/share" class="twitter-share-button" data-count="none" data-via="sukria">Tweet</a><script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script> </div></div><div style="height:0px; width:0px; overflow:hidden;"><a href="http://www.zeitblog.com/?in=plugin">blog tools and plugins from www.zeitblog.com</a></div><p>Related posts:<ol>
<li><a href='http://www.sukria.net/fr/archives/2008/12/18/yoolink-souvre-aux-blogs/' rel='bookmark' title='Yoolink s&#8217;ouvre aux blogs'>Yoolink s&#8217;ouvre aux blogs</a> <small>Depuis aujourd&#8217;hui, les utilisateurs de Yoolink qui disposent d&#8217;un blog...</small></li>
<li><a href='http://www.sukria.net/fr/archives/2007/12/13/extension-firefox-pour-yoolink/' rel='bookmark' title='Extension Firefox pour Yoolink'>Extension Firefox pour Yoolink</a> <small>Yoolink avance à grands pas, et ça fait bougrement plaisir....</small></li>
<li><a href='http://www.sukria.net/fr/archives/2008/12/02/mise-a-jour-de-yoolink-le-partage-de-favoris-plus-fluide/' rel='bookmark' title='Mise à Jour de Yoolink : le partage de favoris plus fluide'>Mise à Jour de Yoolink : le partage de favoris plus fluide</a> <small>Une grosse étape a été franchie ce soir sur yoolink.fr,...</small></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.sukria.net/fr/archives/2008/12/23/nouvelle-version-du-plugin-wordpress-pour-yoolink/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Yoolink s&#8217;ouvre aux blogs</title>
		<link>http://www.sukria.net/fr/archives/2008/12/18/yoolink-souvre-aux-blogs/</link>
		<comments>http://www.sukria.net/fr/archives/2008/12/18/yoolink-souvre-aux-blogs/#comments</comments>
		<pubDate>Thu, 18 Dec 2008 18:12:23 +0000</pubDate>
		<dc:creator>sukria</dc:creator>
				<category><![CDATA[Internet]]></category>
		<category><![CDATA[Plugin]]></category>
		<category><![CDATA[Wordpress]]></category>
		<category><![CDATA[yoolink]]></category>

		<guid isPermaLink="false">http://www.sukria.net/fr/?p=885</guid>
		<description><![CDATA[Depuis aujourd&#8217;hui, les utilisateurs de Yoolink qui disposent d&#8217;un blog (ou d&#8217;un site web classique) peuvent exporter diverses informations de leur profil. Cela est possible grâce aux premiers services fournis par l&#8217;API de Yoolink. Pour l&#8217;occasion, un plugin est proposé aux heureux possesseurs de blogs WordPress pour une intégration complète est indolore (vous pouvez voir &#8230; <a href="http://www.sukria.net/fr/archives/2008/12/18/yoolink-souvre-aux-blogs/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Depuis aujourd&#8217;hui, les utilisateurs de Yoolink qui disposent d&#8217;un blog (ou d&#8217;un site web classique) peuvent exporter diverses informations de leur profil.</p>
<p>Cela est possible grâce <a href="http://www.yoolink.fr/webmaster">aux premiers services fournis par l&#8217;API de Yoolink</a>. Pour l&#8217;occasion, un plugin est proposé aux heureux possesseurs de blogs WordPress pour une intégration complète est indolore (vous pouvez voir ce plugin à l&#8217;oeuvre sur ce blog, notamment sur la sidebar).</p>
<p>Pour plus de détails sur le sujet, je vous invite à consuilter <a href="http://www.yoolink.fr/blog">le blog officiel de Yoolink</a>, ou un article complet expliquera tout ça.</p>
<div id='teoShare' ><div id='teo2Google'>
		<!-- Place this tag where you want the +1 button to render -->
		<g:plusone size='tall' annotation='none'></g:plusone>

		<!-- Place this render call where appropriate -->
		<script type='text/javascript'>
		  (function() {
			var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true;
			po.src = 'https://apis.google.com/js/plusone.js';
			var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s);
		  })();
		</script>
		</div><div id="teoTweet" >
		<a href="http://twitter.com/share" class="twitter-share-button" data-count="none" data-via="sukria">Tweet</a><script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script> </div></div><div style="height:0px; width:0px; overflow:hidden;"><a href="http://www.zeitblog.com/?in=plugin">blog tools and plugins from www.zeitblog.com</a></div><p>Related posts:<ol>
<li><a href='http://www.sukria.net/fr/archives/2008/12/23/nouvelle-version-du-plugin-wordpress-pour-yoolink/' rel='bookmark' title='Nouvelle version du plugin WordPress pour Yoolink'>Nouvelle version du plugin WordPress pour Yoolink</a> <small>Une mise à jour du plugin WordPress est disponible depuis...</small></li>
<li><a href='http://www.sukria.net/fr/archives/2007/12/13/extension-firefox-pour-yoolink/' rel='bookmark' title='Extension Firefox pour Yoolink'>Extension Firefox pour Yoolink</a> <small>Yoolink avance à grands pas, et ça fait bougrement plaisir....</small></li>
<li><a href='http://www.sukria.net/fr/archives/2008/12/02/mise-a-jour-de-yoolink-le-partage-de-favoris-plus-fluide/' rel='bookmark' title='Mise à Jour de Yoolink : le partage de favoris plus fluide'>Mise à Jour de Yoolink : le partage de favoris plus fluide</a> <small>Une grosse étape a été franchie ce soir sur yoolink.fr,...</small></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.sukria.net/fr/archives/2008/12/18/yoolink-souvre-aux-blogs/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

