<?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>Juozas devBlog &#187; repository</title>
	<atom:link href="http://dev.juokaz.com/tag/repository/feed" rel="self" type="application/rss+xml" />
	<link>http://dev.juokaz.com</link>
	<description>Random ideas, scripts and facts</description>
	<lastBuildDate>Mon, 22 Mar 2010 10:48:42 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Using Phing to sync files with shared hosting</title>
		<link>http://dev.juokaz.com/php/using-phing-to-synchronize-files</link>
		<comments>http://dev.juokaz.com/php/using-phing-to-synchronize-files#comments</comments>
		<pubDate>Fri, 27 Feb 2009 19:14:20 +0000</pubDate>
		<dc:creator>Juozas</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Servers]]></category>
		<category><![CDATA[ant]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[blogs]]></category>
		<category><![CDATA[build]]></category>
		<category><![CDATA[code in the hole]]></category>
		<category><![CDATA[ftp]]></category>
		<category><![CDATA[head]]></category>
		<category><![CDATA[id]]></category>
		<category><![CDATA[phing]]></category>
		<category><![CDATA[php::impact]]></category>
		<category><![CDATA[project]]></category>
		<category><![CDATA[repository]]></category>
		<category><![CDATA[revision]]></category>
		<category><![CDATA[subversion]]></category>
		<category><![CDATA[svn]]></category>
		<category><![CDATA[upload]]></category>

		<guid isPermaLink="false">http://dev.juokaz.com/?p=284</guid>
		<description><![CDATA[Phing is a project build system. It&#8217;s wonderful tool to automate every-days task by writing build scenario &#8211; Phing can do everything what can be done with PHP or Linux console applications. Today I was trying to use it in shared hosting server, but as you will see, Phing can&#8217;t do a lot of it&#8217;s [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://phing.info/trac/"><img class="size-full wp-image-292" style="float: right;" title="Phing" src="http://dev.juokaz.com/wp-content/uploads/2009/02/logo.gif" alt="Phing" width="197" height="58" />Phing</a> is a project build system. It&#8217;s wonderful tool to automate every-days task by writing build scenario &#8211; Phing can do everything what can be done with PHP or Linux console applications. Today I was trying to use it in shared hosting server, but as you will see, Phing can&#8217;t do a lot of it&#8217;s functionality without direct access to server (over shh for example).</p>
<p><a href="http://phpimpact.wordpress.com/">PHP::Impact blog</a> has very nice <a href="http://phpimpact.wordpress.com/2008/07/21/filesynctask-using-phing-to-synchronize-files-and-directories/">article</a> about remote files synchronization. Given FileSyncTask library uses <a href="http://samba.anu.edu.au/rsync/"><em>rsync</em></a>, console utility, which is de-facto standard for syncing files. Everything sounds great, but things get worse, when you try to sync files in shared hosting environment, where only FTP is available.</p>
<p><a href="http://codeinthehole.com">Code in the hole</a> some months ago posted <a href="http://codeinthehole.com/archives/13-Deploying-to-a-shared-hosting-environment-using-Phing.html">solution</a> which uses Net_FTP (FTP functionality wrapper) package to upload files to server. I decided to try given solution, so I modified it to download source code from SVN first and then upload them. My tests code:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;project</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;project&quot;</span> <span style="color: #000066;">basedir</span>=<span style="color: #ff0000;">&quot;.&quot;</span> <span style="color: #000066;">default</span>=<span style="color: #ff0000;">&quot;build&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">file</span>=<span style="color: #ff0000;">&quot;build.properties&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;fileset</span> <span style="color: #000066;">dir</span>=<span style="color: #ff0000;">&quot;${sync.projectdir}/&quot;</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;files.main&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;include</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;**/*&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
        <span style="color: #808080; font-style: italic;">&lt;!-- netbeans project folder --&gt;</span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;exclude</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;nbproject/**&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/fileset<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;target</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;build&quot;</span> <span style="color: #000066;">depends</span>=<span style="color: #ff0000;">&quot;svnexport,deploy-application-files&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;target</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;deploy-application-files&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;echo</span> <span style="color: #000066;">msg</span>=<span style="color: #ff0000;">&quot;Deploying application files&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;phingcall</span> <span style="color: #000066;">target</span>=<span style="color: #ff0000;">&quot;deploy&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
	    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;deploy.fileset.refid&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;files.main&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/phingcall<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/target<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;target</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;deploy&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;ftpdeploy</span></span>
<span style="color: #009900;">	    <span style="color: #000066;">host</span>=<span style="color: #ff0000;">&quot;${ftp.host}&quot;</span> <span style="color: #000066;">port</span>=<span style="color: #ff0000;">&quot;${ftp.port}&quot;</span></span>
<span style="color: #009900;">	    <span style="color: #000066;">username</span>=<span style="color: #ff0000;">&quot;${ftp.username}&quot;</span> <span style="color: #000066;">password</span>=<span style="color: #ff0000;">&quot;${ftp.password}&quot;</span></span>
<span style="color: #009900;">	    <span style="color: #000066;">dir</span>=<span style="color: #ff0000;">&quot;${ftp.dir}&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
	    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;fileset</span> <span style="color: #000066;">refid</span>=<span style="color: #ff0000;">&quot;${deploy.fileset.refid}&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/ftpdeploy<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/target<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;target</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;svnexport&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;delete</span> <span style="color: #000066;">dir</span>=<span style="color: #ff0000;">&quot;${sync.projectdir}&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
&nbsp;
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;svnexport</span></span>
<span style="color: #009900;">	    <span style="color: #000066;">username</span>=<span style="color: #ff0000;">&quot;${svn.username}&quot;</span> <span style="color: #000066;">password</span>=<span style="color: #ff0000;">&quot;${svn.password}&quot;</span></span>
<span style="color: #009900;">	    <span style="color: #000066;">nocache</span>=<span style="color: #ff0000;">&quot;true&quot;</span> <span style="color: #000066;">force</span>=<span style="color: #ff0000;">&quot;true&quot;</span></span>
<span style="color: #009900;">	    <span style="color: #000066;">repositoryurl</span>=<span style="color: #ff0000;">&quot;${svn.repo}&quot;</span> <span style="color: #000066;">todir</span>=<span style="color: #ff0000;">&quot;${sync.projectdir}&quot;</span></span>
<span style="color: #009900;">        <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/target<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/project<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>Project was successfully uploaded, but it took more than half an hour (I have university Internet which is very fast). Problem is, it doesn&#8217;t check for files changes &#8211; it just uploads every single file in <em>fileset</em>. I don&#8217;t blame anyone, FTP is not made for syncing files and uploading huge amount of tiny files is very slow. We need other solution.</p>
<p>I have come up with another idea, which works by:</p>
<ol>
<li>Get <em>last-revision-id</em> from production server</li>
<li>Download modified files (difference from last-revision-id to HEAD) from SVN repository</li>
<li>Upload modified files</li>
<li>Change<em> last-revision-id</em> to current ID</li>
</ol>
<p>It works in theory and can be really simply implemented with Phing, but it&#8217;s still not very good solution. There is too much trust for one file (<em>last-revision-id</em>). Unless you can make sure that nobody will touch any files inside server without using Phing build script, things can easily brake. That&#8217;s why I haven&#8217;t tried it.</p>
<p>Have you used anything like this? Currently I&#8217;m thinking about moving to different server, because these limits (no <a href="http://en.wikipedia.org/wiki/Secure_Shell">ssh</a>) for bigger projects creates massive headaches. I have came up with some hacks, as written above, but they are too sensitive and just mimics actual synchronization.</p>
]]></content:encoded>
			<wfw:commentRss>http://dev.juokaz.com/php/using-phing-to-synchronize-files/feed</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Automatic SVN Revision number in source code</title>
		<link>http://dev.juokaz.com/php/automatic-svn-revision-number-in-source-code</link>
		<comments>http://dev.juokaz.com/php/automatic-svn-revision-number-in-source-code#comments</comments>
		<pubDate>Mon, 09 Feb 2009 16:57:17 +0000</pubDate>
		<dc:creator>Juozas</dc:creator>
				<category><![CDATA[HTML]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[automatic]]></category>
		<category><![CDATA[cache]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[extract]]></category>
		<category><![CDATA[number]]></category>
		<category><![CDATA[repository]]></category>
		<category><![CDATA[reverse]]></category>
		<category><![CDATA[revision]]></category>
		<category><![CDATA[source code]]></category>
		<category><![CDATA[style.css]]></category>
		<category><![CDATA[stylesheet]]></category>
		<category><![CDATA[svn]]></category>

		<guid isPermaLink="false">http://dev.juokaz.com/?p=59</guid>
		<description><![CDATA[Versioning is essential for source code control and there is fabulous amount of possible benefits. One of the possibilities is to let your source code know and make decisions using it&#8217;s version (revision) number.
For example, if you change your CSS code, you want users to get it immediately and not after their browser cached version [...]]]></description>
			<content:encoded><![CDATA[<p>Versioning is essential for source code control and there is fabulous amount of possible benefits. One of the possibilities is to let your source code know and make decisions using it&#8217;s version (revision) number.</p>
<p>For example, if you change your CSS code, you want users to get it immediately and not after their browser cached version expires. One of possible ways, to force browser to load new version, is to add version number as a query string.</p>
<p>Normal HTML stylesheet code looks like this:<br />
<em>&lt;link rel=&#8221;stylesheet&#8221; href=&#8221;/style.css&#8221; type=&#8221;text/css&#8221; media=&#8221;screen&#8221; /&gt;</em>,<br />
and with added version number:<br />
<em>&lt;link rel=&#8221;stylesheet&#8221; href=&#8221;/style.css<strong>?91</strong>&#8221; type=&#8221;text/css&#8221; media=&#8221;screen&#8221; /&gt;.</em></p>
<p>Browsers will always grab new stylesheet after each url change &#8211; you can increase version number by +1, add date, etc. Let it be our goal &#8211; use SVN functionality to automatically tag stylesheets.</p>
<p>First thing to do, is to insert <strong>$Rev$</strong> in source code of selected file (mine: <em>style.css</em>). Then go to console and set SVN property:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">svn</span> propset <span style="color: #c20cb9; font-weight: bold;">svn</span>:keywords <span style="color: #ff0000;">&quot;Rev&quot;</span> style.css</pre></div></div>

<p>Now, after each commit to repository, this keyword will be replaced by <strong>$Rev: <em>NUMBER</em> $</strong>, where NUMBER is current revision number. Next thing is to use PHP to read revision number from <em>style.css</em> source and append it to style URL.</p>
<p>Reading revision number is the easiest part, because if you store revision number in first line, you can quite efficiently grab only that part of source and <a href="http://uk2.php.net/preg_match">preg_match</a>/simple match number. Sample script looks like this:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">//reading stream</span>
<span style="color: #000088;">$handle</span> <span style="color: #339933;">=</span> <span style="color: #990000;">fopen</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;style.css&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;r&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">//read first line, TODO: check if it's not empty, etc.</span>
<span style="color: #000088;">$first_line</span> <span style="color: #339933;">=</span> <span style="color: #990000;">fgets</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$handle</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">//extract revision number, chosen format: &quot;/* $Rev: 1424314 $ */&quot;</span>
<span style="color: #000088;">$revid</span> <span style="color: #339933;">=</span> <span style="color: #990000;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$first_line</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">9</span><span style="color: #339933;">,</span> <span style="color: #339933;">-</span><span style="color: #cc66cc;">6</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">//print generated link</span>
<span style="color: #b1b100;">print</span> <span style="color: #0000ff;">&quot;style.css? &quot;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$revid</span><span style="color: #339933;">;</span></pre></div></div>

<p>You can easily modify and transform it to function, but key concept will be the same. However, this method is useful only to show revision number of one file, because revision number changes only after commit. For whole project revision number there are better solutions.</p>
<p>I would love to hear your ideas, because I brainstormed this one only a few days ago and I still think it can be made more efficiently. One of possible enchantments would be using build script, but I&#8217;m still searching for more simpler solutions.</p>
]]></content:encoded>
			<wfw:commentRss>http://dev.juokaz.com/php/automatic-svn-revision-number-in-source-code/feed</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
	</channel>
</rss>
