<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss 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/" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">

<channel>
	<title>zoe.vc</title>
	
	<link>http://www.zoe.vc</link>
	<description>development &amp; freelancing blog</description>
	<lastBuildDate>Mon, 02 Aug 2010 08:51:08 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=5582</generator>
		<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/zoevc" /><feedburner:info uri="zoevc" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><geo:lat>51.050</geo:lat><geo:long>13.750</geo:long><item>
		<title>Show Django AdminSite fields depending on the current user</title>
		<link>http://feedproxy.google.com/~r/zoevc/~3/XedMmY5r_us/</link>
		<comments>http://www.zoe.vc/2010/show-django-adminsite-fields-depending-on-the-current-user/#comments</comments>
		<pubDate>Mon, 02 Aug 2010 08:36:35 +0000</pubDate>
		<dc:creator>Alex (zoe.vc)</dc:creator>
				<category><![CDATA[Django]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[admin]]></category>
		<category><![CDATA[adminsite]]></category>
		<category><![CDATA[custom]]></category>
		<category><![CDATA[dependency]]></category>
		<category><![CDATA[field]]></category>
		<category><![CDATA[modeladmin]]></category>
		<category><![CDATA[softdelete]]></category>

		<guid isPermaLink="false">http://www.zoe.vc/?p=153</guid>
		<description><![CDATA[Introduction The auto-created AdminSite in Django is a nifty feature for creating an administrative view of your model classes. Somehow it is not perfect, even if you want to customized it. To guide you to my problem and solution you've to know, that I implemented the SoftDelete behaviour for model classes as described by Greg [...]]]></description>
			<content:encoded><![CDATA[<h3>Introduction</h3>
<p>The auto-created AdminSite in Django is a nifty feature for creating an administrative view of your model classes. Somehow it is not perfect, even if you want to customized it. To guide you to my problem and solution you've to know, that I implemented the <a href="http://codespatter.com/2009/07/01/django-model-manager-soft-delete-how-to-customize-admin/">SoftDelete behaviour for model classes as described by Greg Allard</a>. It simply adds a 'deleted' field to each model marking it as deleted if its deleted in the admin site (or in some application) but never really gets deleted from the database. So in the admin site there is this field 'deleted' displayed, if you have configured it.</p>
<h3>The Problem</h3>
<p>My project has 2 different 'usergroups', the editors and the superusers. Superusers should see the 'deleted' fields, the others not. Unfortunatly that is not possible out of the box with Django.</p>
<p><span id="more-153"></span></p>
<h3>The solution</h3>
<p>I'm not the first one struggling with the user dependent display of model fields. <a href="http://lukeplant.me.uk/blog/posts/django-admin-hack-fields-varying-with-user-permissions/">Luke Plant found a solution for an older version of Django</a> dealing with the field display in the add/change view. Later he <a href="http://lukeplant.me.uk/blog/posts/django-newforms-admin-upgrade/">updated the thing</a> as the Django version grew. I adapted some lines of his last code for the add/change view and wrote something new to also handle the history view (that lists all model ob jects). I divided it into 2 subclasses of admin.ModelAdmin for better abstraction: one for the handling the user dependent queryset for SoftDelete and one for the display of the fields.</p>
<h4>SoftDeleteModelAdmin</h4>
<p>As the superusers should see the deleted field and the others not, we'll only query for the field if there is a superuser. Quite logical. The class uses the proper queryset and also returns a deleted objects if directly requested (<a href="http://snipt.org/Wngj" target="_blank">beautyfied code @ snipt.org</a>):</p>
<pre class="python">class SoftDeleteModelAdmin(admin.ModelAdmin):
  def queryset(self, request):
    if request.user.is_superuser:
      qs = self.model._default_manager.all_with_deleted()
    else:
      qs = self.model._default_manager.all()
    ordering = self.ordering or ()
    if ordering:
      qs = qs.order_by(*ordering)
    return qs

  ## If a specific record was requested, return it even if it's deleted
  def get(self, *args, **kwargs):
    return self.all_with_deleted().get(*args, **kwargs)

  ## If pk was specified as a kwarg, return even if it's deleted
  def filter(self, *args, **kwargs):
    if 'pk' in kwargs:
       return self.all_with_deleted().filter(*args, **kwargs)
    return self.get_query_set().filter(*args, **kwargs)</pre>
<h4>UserDependentModelAdmin</h4>
<p>For the display of the field depending on the current user you have to inherit from the UserDependentModelAdmin class as listed below. Adjust the ModelAdmin class and add 'list_display_editors' (for all users != superuser) and 'list_display_superuser' (for superusers) tuples with the field names for the appropriate user (I'll only use a field called 'name' and the 'deleted' field):</p>
<pre class="python">class SomeAdmin(SoftDeleteModelAdmin, UserDependentModelAdmin):
  list_display = ()

  # editor fields and fieldsets
  list_display_editor = ('name',)
  fieldsets_editor = [(None, { 'fields': ['name'] })]

  # superuser fields and fieldsets
  list_display_superuser = list_display_editor + ('deleted',)
  fieldsets_superuser = [(None, { 'fields': ['name', 'deleted'] })]</pre>
<p>All other magic is done by the UserDependentModelAdmin class. It simply changes the list_display field in the history view depending on the user and sets some prerequisites.  The 'get_fieldset' method returns the fields for the add/change view, this is nearly the same code Luke Plant wrote. (<a href="http://snipt.org/Wngh" target="_blank">beautified code @ snipt.org</a>)</p>
<pre class="python">csrf_protect_m = method_decorator(csrf_protect)

## User dependent admin model.
# This class allows to specify tuples of the listed fields and displayed fieldsets
# for the editors and superusers.
class UserDependentModelAdmin(admin.ModelAdmin):
  ## Class constructor, adding actions an/or links for the user fields.
  # @param model      the model the admin site is created for
  # @param admin_site the admin site
  def __init__(self, model, admin_site):
    # this is performed regularly on the list_display tuple
    # do the same for the additional list_display fields
    self._add_actions_and_links_for_list_display('editor')
    self._add_actions_and_links_for_list_display('superuser')
    super(UserDependentModelAdmin, self).__init__(model, admin_site)

  ## Adds actions and/or links for the list_display tuple of the given user
  # definid list_type.
  # @param list_type  the list_display type, currently 'editor' for editors or 'superuser' for superuser
  def _add_actions_and_links_for_list_display(self, list_type):
    if 'action_checkbox' not in getattr(self, 'list_display_' + list_type) and self.actions is not None:
      setattr(
        self,
       'list_display_' + list_type,
       ['action_checkbox'] +  list(getattr(self, 'list_display_' + list_type))
      )
    if not self.list_display_links:
    for name in getattr(self, 'list_display_' + list_type):
      if name != 'action_checkbox':
        self.list_display_links = [name]
      break

  ## View for listing the models.
  # Adjusts the list_display tuple according to the current user.
  # @param request        the sent request
  # @param extra_content  an additional context
  @csrf_protect_m
  def changelist_view(self, request, extra_context=None):
    if request.user.is_superuser:
      self.list_display = self.list_display_superuser
    else:
      self.list_display = self.list_display_editor
    return super(UserDependentModelAdmin, self).changelist_view(request, extra_context=extra_context)

  ## Returns the fieldsets depending on the user.
  # @param request    the sent request
  # @param obj        the model object if already persisted
  def get_fieldsets(self, request, obj=None):
    user = request.user
    if user is None or user.is_anonymous():
      # never get here normally
      return ()
    else:           
      if user.is_superuser:
        return self.fieldsets_superuser
      else:
        return self.fieldsets_editor</pre>
<img src="http://feeds.feedburner.com/~r/zoevc/~4/XedMmY5r_us" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.zoe.vc/2010/show-django-adminsite-fields-depending-on-the-current-user/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.zoe.vc/2010/show-django-adminsite-fields-depending-on-the-current-user/</feedburner:origLink></item>
		<item>
		<title>Simple MySQL Backup at Google Code</title>
		<link>http://feedproxy.google.com/~r/zoevc/~3/_g1GRj_M2pw/</link>
		<comments>http://www.zoe.vc/2009/simple-mysql-backup-at-google-code/#comments</comments>
		<pubDate>Sun, 27 Sep 2009 13:02:29 +0000</pubDate>
		<dc:creator>Alex (zoe.vc)</dc:creator>
				<category><![CDATA[Backup]]></category>
		<category><![CDATA[Infrastructure]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Scripting Languages]]></category>
		<category><![CDATA[gzip]]></category>
		<category><![CDATA[mySQL]]></category>
		<category><![CDATA[mysqldump]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[zip]]></category>

		<guid isPermaLink="false">http://www.zoe.vc/?p=143</guid>
		<description><![CDATA[A while ago I wrote an article about a script I created to backup databases. Since then I had to make little changes and decided to put it to Google code as Open-Source-Project and released the new version 0.1.1 with some minor changes. If you're interested in the script, head over to its project page [...]]]></description>
			<content:encoded><![CDATA[<p>A while ago I wrote an article about a script I created to backup databases. Since then I had to make little changes and decided to put it to Google code as Open-Source-Project and released the new version 0.1.1 with some minor changes.</p>
<p>If you're interested in the script, head over to<a href="http://code.google.com/p/simple-mysql-backup/"> its project page</a> and check the appropriate pages like the <a href="http://code.google.com/p/simple-mysql-backup/wiki/Changelog">Changelog</a> and the<a href="http://code.google.com/p/simple-mysql-backup/wiki/InstallationAndUsage"> Installation and Requirements page</a>. Feel free <a href="http://code.google.com/p/simple-mysql-backup/downloads/list">to download</a> and <a href="http://www.zoe.vc/2009/simple-mysql-backup-at-google-code/#respond">comment  it</a>.</p>
<img src="http://feeds.feedburner.com/~r/zoevc/~4/_g1GRj_M2pw" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.zoe.vc/2009/simple-mysql-backup-at-google-code/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<feedburner:origLink>http://www.zoe.vc/2009/simple-mysql-backup-at-google-code/</feedburner:origLink></item>
		<item>
		<title>zoe.vc is back</title>
		<link>http://feedproxy.google.com/~r/zoevc/~3/hgZ0iyUc1LM/</link>
		<comments>http://www.zoe.vc/2009/zoe-vc-is-back/#comments</comments>
		<pubDate>Wed, 02 Sep 2009 11:57:30 +0000</pubDate>
		<dc:creator>Alex (zoe.vc)</dc:creator>
				<category><![CDATA[Common]]></category>
		<category><![CDATA[server]]></category>

		<guid isPermaLink="false">http://www.zoe.vc/?p=104</guid>
		<description><![CDATA[Finally we made it to the new server. Unfortunatly all special characters are broken, but I'll fix that later. And hopefully I'll have same time to post new content]]></description>
			<content:encoded><![CDATA[<p>Finally we made it to the new server. Unfortunatly all special characters are broken, but I'll fix that later. And hopefully I'll have same time to post new content <img src='http://www.zoe.vc/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<img src="http://feeds.feedburner.com/~r/zoevc/~4/hgZ0iyUc1LM" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.zoe.vc/2009/zoe-vc-is-back/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.zoe.vc/2009/zoe-vc-is-back/</feedburner:origLink></item>
		<item>
		<title>Probably Site Downtime</title>
		<link>http://feedproxy.google.com/~r/zoevc/~3/AMHxfz3nrfI/</link>
		<comments>http://www.zoe.vc/2009/probably-site-downtime/#comments</comments>
		<pubDate>Sun, 30 Aug 2009 15:00:54 +0000</pubDate>
		<dc:creator>Alex (zoe.vc)</dc:creator>
				<category><![CDATA[Common]]></category>
		<category><![CDATA[server]]></category>

		<guid isPermaLink="false">http://www.zoe.vc/?p=101</guid>
		<description><![CDATA[Howdy! As I'm moving the domain to a new server these days it could be possible that zoe.vc isn't reachable for some hours or even days. So don't be confused - everything will be alright after the movement is finished. Comments are disabled meanwhile. Thanks for your understanding!]]></description>
			<content:encoded><![CDATA[<p>Howdy!</p>
<p>As I'm moving the domain to a new server these days it could be possible that zoe.vc isn't reachable for some hours or even days. So don't be confused - everything will be alright after the movement is finished. Comments are disabled meanwhile.</p>
<p>Thanks for your understanding!</p>
<img src="http://feeds.feedburner.com/~r/zoevc/~4/AMHxfz3nrfI" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.zoe.vc/2009/probably-site-downtime/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.zoe.vc/2009/probably-site-downtime/</feedburner:origLink></item>
		<item>
		<title>The Bug Genie 2 SVN Integration on Windows with VisualSVN Server</title>
		<link>http://feedproxy.google.com/~r/zoevc/~3/214_ue0PP_g/</link>
		<comments>http://www.zoe.vc/2009/the-bug-genie-2-svn-integration-on-windows-with-visualsvn-server/#comments</comments>
		<pubDate>Sun, 12 Jul 2009 15:02:31 +0000</pubDate>
		<dc:creator>Alex (zoe.vc)</dc:creator>
				<category><![CDATA[Bugtracker]]></category>
		<category><![CDATA[Infrastructure]]></category>
		<category><![CDATA[bugs2]]></category>
		<category><![CDATA[server]]></category>
		<category><![CDATA[svn]]></category>
		<category><![CDATA[svn_integration]]></category>
		<category><![CDATA[thebuggenie]]></category>
		<category><![CDATA[visualsvn]]></category>
		<category><![CDATA[windows]]></category>

		<guid isPermaLink="false">http://www.zoe.vc/?p=93</guid>
		<description><![CDATA[In my local development environment at home I use The Bug Genie 2 for bugtracking. The tool is quiet cool, although the german translation is totally broken (I fixed it and send it to them, let's see what happens). It comes with a module called "svn_integration" for integrating SVN into the tracker to automatically have [...]]]></description>
			<content:encoded><![CDATA[<p>In my local development environment at home I use <a href="http://www.thebuggenie.com/">The Bug Genie 2</a> for bugtracking. The tool is quiet cool, although the german translation is totally broken (I fixed it and send it to them, let's see what happens). It comes with a module called "svn_integration" for integrating SVN into the tracker to automatically have updated issues when the SVN comments contain special keywords. That's quiet cool, too, but unfortunatly does not work for me.</p>
<p>I'm using Windows Vista Business x64 as os and for SVN the wonderful, free and easy <a href="http://www.visualsvn.com/server/">VisualSVN Server</a>. Next ugly thing on The Bug Genie is that there is no documentation for the modules. I found an <a href="http://www.thebuggenie.com/forum/viewtopic.php?f=4&amp;t=30">entry in the forums</a> how to use the integration in windows, but that did not work out of the box. But the code is already within the module, what is good.</p>
<p>So open <strong>modules/svn_integration/post_commit.php </strong>from your buggenie installation directory and adjust this line with your path to the bugtracker installation dir:</p>
<pre class="php"><a href="http://www.php.net/define"><span style="color: #000066;">define</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'BUGS2_INCLUDE_PATH'</span>, <span style="color: #ff0000;">'D:<span style="color: #000099; font-weight: bold;">\\</span>xampp<span style="color: #000099; font-weight: bold;">\\</span>htdocs<span style="color: #000099; font-weight: bold;">\\</span>bugs<span style="color: #000099; font-weight: bold;">\\</span>'</span><span style="color: #66cc66;">&#41;</span>;</pre>
<p>Then create a batch file in the same directory called <strong>post-commit.bat</strong>. You can see the source below, copy it and adjust the following variables. I used the code from the forum post and adjusted it a little. Remember that urls with whitespaces do not work, create a symlink or rename your directories:</p>
<ul>
<li>Path to svnlook.exe (you see my VisualSVN Server resides in <em>D:\VisualSVN_Server</em>, the default location <em>C:\Program Files (x86)\VisualSVN Server</em> does not work because of the whitespaces) VisualSVN Server has all the svn tools in its <strong>bin</strong> directory.</li>
</ul>
<pre>SET SVNLOOK=D:\VisualSVN_Server\bin\svnlook.exe</pre>
<ul>
<li>The path to your php executable. I used XAMPP, so it is in <strong>D:\xampp\php\php.exe</strong> if installed in root on drive D.</li>
</ul>
<pre>SET PHP=D:\xampp\php\php.exe</pre>
<ul>
<li>The path to your SVN directory. This is where svn stores its data.</li>
</ul>
<pre>SET SVN_PATH=D:\svn\</pre>
<ul>
<li>The post-commit hook we create later takes two arguments from VisualSVN Server, the path and the revision. Unfortunatly VisualSVN Server uses the url as path which collides with the svnlook command we use to determine if a bug was mentioned in a revision comment, as svnlook wants the real file path.<br />
So we have to adjust the url to a path. As there is no real substring functionality for windows batch (or I did not search long enough) we simply count the length of our SVN url. In my case VisualSVN Server listens at <em>https://amanda:8443/svn/</em>, so a repository would be at <em>https://amanda:8443/svn/my_repos</em>. The server root (<em>https://amanda:8443/svn/) </em>has a length  length of 24. Change the 24 to the length of your url. The batch then combines the SVN_PATH and your repository path to the local path, <em>D:\svn\myrepos</em> in my case here.</li>
</ul>
<pre>SET REPOS=%REPOS:~24%</pre>
<ul>
<li>Once again, set the path to your installation directory of the bugtracker (replace <em>D:\xampp\htdocs\bugs</em> with your path):</li>
</ul>
<pre>%PHP% -f "D:\xampp\htdocs\bugs\modules\svn_integration\post-commit.php" "%AUTHOR%" "%REV%" "%COMMIT_MSG%" "%CHANGED%"</pre>
<p>After your saved the file, open VisualSVN Server and the properties of your repository. Select the the <strong>Hooks</strong> tab and doubleclick the <strong>Post-commit hook</strong>. Enter the path to the batch file with the 2 arguments path and revision, in my case I entered "<strong>D:\xampp\htdocs\bugs\modules\svn_integration\post-commit.bat %1 %2</strong>", where %1 is the repository path and %2 the revision number.</p>
<p>Finally you have to install either <a href="http://websvn.tigris.org/">WebSVN</a> (which I prefer) or <a href="http://www.viewvc.org/">ViewVC</a> and specify the path to your repository (in my case it is <em>http://localhost/websvn/listing.php?repname=my_repos&amp;</em>) in The Bug Genie module settings for svn_integration.</p>
<p><span style="text-decoration: underline;"><strong>One final and important hint:</strong></span> your user in the bugtracker has to have the same username as in SVN. By default, the first user in the tracker has the username "Administrator". My SVN user does not have the name "Administrator", so I logged out of the tracker, changed the property "<strong>uname</strong>" of the MySQL table "<strong>bugs2_users</strong>" for the admin to my SVN username, logged in and then everything worked fine.</p>
<p>As always, feel free to add comments and spread the word</p>
<p>And here the post-commit.bat code:</p>
<pre>@echo off
SET REV=%2
SET REPOS=%1

REM path to svnlook (remember that paths with whitespace do not work e.g. C:\Program Files --&gt; use mklink to create a path without)
SET SVNLOOK=D:\VisualSVN_Server\bin\svnlook.exe

REM path to php executable
SET PHP=D:\xampp\php\php.exe

REM path to svn (not url!)
SET SVN_PATH=D:\svn\

REM maps the svn url to the svn path - straightforward but the easiest way
REM replace with the length of your svn url e.g. 24 for https://amanda:8443/svn/
SET REPOS=%REPOS:~24%

SET REPOS=%SVN_PATH%%REPOS:/=\%

%SVNLOOK% log -r %REV% "%REPOS%" &gt; COMMIT_MSG
REM SET THE COMMIT_MSG FROM THE FILE. The file is expected to contain only one line with this value
FOR /F "delims=" %%A IN (COMMIT_MSG) DO SET COMMIT_MSG=%%A
echo COMMIT_MSG=%COMMIT_MSG%

%SVNLOOK% changed -r %REV% "%REPOS%" &gt; CHANGED
REM SET THE CHANGED FROM THE FILE. The file is expected to contain only one line with this value
FOR /F %%A IN (CHANGED) DO SET CHANGED=%%A
echo COMMIT_MSG=%CHANGED%

%SVNLOOK% author -r %REV% "%REPOS%" &gt; AUTHOR
REM SET THE AUTHOR FROM THE FILE. The file is expected to contain only one line with this value
FOR /F %%A IN (AUTHOR) DO SET AUTHOR=%%A
echo COMMIT_MSG=%AUTHOR%

%PHP% -r "echo urlencode($argv[1]);" "%COMMIT_MSG%" &gt; URL_COMMIT_MSG
REM SET THE URL_COMMIT_MSG FROM THE FILE. The file is expected to contain only one line with this value
FOR /F %%A IN (URL_COMMIT_MSG) DO SET URL_COMMIT_MSG=%%A
echo COMMIT_MSG=%URL_COMMIT_MSG%

%PHP% -f "D:\xampp\htdocs\bugs\modules\svn_integration\post-commit.php" "%AUTHOR%" "%REV%" "%COMMIT_MSG%" "%CHANGED%"</pre>
<img src="http://feeds.feedburner.com/~r/zoevc/~4/214_ue0PP_g" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.zoe.vc/2009/the-bug-genie-2-svn-integration-on-windows-with-visualsvn-server/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.zoe.vc/2009/the-bug-genie-2-svn-integration-on-windows-with-visualsvn-server/</feedburner:origLink></item>
		<item>
		<title>MySQL Backup Skript mit Emailversand.</title>
		<link>http://feedproxy.google.com/~r/zoevc/~3/ugf9p2_WC7k/</link>
		<comments>http://www.zoe.vc/2009/mysql-backup-skript-mit-emailversand/#comments</comments>
		<pubDate>Sat, 27 Jun 2009 17:30:41 +0000</pubDate>
		<dc:creator>Alex (zoe.vc)</dc:creator>
				<category><![CDATA[Backup]]></category>
		<category><![CDATA[Infrastructure]]></category>
		<category><![CDATA[Email]]></category>
		<category><![CDATA[mySQL]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.zoe.vc/?p=69</guid>
		<description><![CDATA[Vor kurzem habe ich ein schönes Skript zum Sichern einer MySQL-Datenbank und anschließendem Versenden des Backups per Email hier gefunden. Das Skript ist an sich ganz gut, aber mir hat es strukturell nicht gefallen, da man die Datenbankzugangsdaten inline eintragen muss und es ausserdem nur für eine Datenbank funktioniert. Deswegen habe ich das ganze ein [...]]]></description>
			<content:encoded><![CDATA[<div class="jLanguage">
<ul>
<li><a href="?lan=english"><img alt="english" src="http://www.zoe.vc/wp-content/plugins/jLanguage/icons/en.png" /></a></li>
<li><a href="?lan=german"><img alt="german" src="http://www.zoe.vc/wp-content/plugins/jLanguage/icons/de.png" /></a></li>
</ul>
</div>
<p>Vor kurzem habe ich ein schönes Skript zum Sichern einer MySQL-Datenbank und anschließendem Versenden des Backups per Email <a href="http://www.gmeditor.com/wiki/code-downloads/mysql-backup/">hier</a> gefunden.</p>
<p>Das Skript ist an sich ganz gut, aber mir hat es strukturell nicht gefallen, da man die Datenbankzugangsdaten inline eintragen muss und es ausserdem nur für eine Datenbank funktioniert. Deswegen habe ich das ganze ein wenig umgeschrieben und stelle das hier gerne zum Download bereit.</p>
<p>Was kann es?</p>
<ul>
<li>Backup mehrerer Datenbanken</li>
<li>Versenden der Backups an mehrere Empfänger</li>
</ul>
<p>Es wird dabei pro Datenbank eine Email versendet und auf dem Server bleiben keine Dateien liegen. Das ganze ist auch noch einfach zu konfigurieren.</p>
<p>Wie benutze ich das?</p>
<ul>
<li><a href="http://www.zoe.vc/misc/mysqlbackup-0.1.rar">Aktuelle Version (0.1) herunterladen</a></li>
<li>Daten in backup.php anpassen (ist alles kommentiert)</li>
<li>alles in ein Verzeichnis deiner Wahl hochladen</li>
<li>ggf. einen cronjob anlegen, der das Skript periodisch ausführen</li>
</ul>
<p>Hier die backup.php, welche die entsprechenden Klassen aufruft und das Backup anstößt (ist auch im Download mit enthalten):</p>
<pre class="php"><a href="http://www.php.net/ini_set"><span style="color: #000066;">ini_set</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'error_reporting'</span>, <span style="color: #000000; font-weight: bold;">E_ALL</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #808080; font-style: italic;">// include the files</span>
<span style="color: #b1b100;">require_once</span> <span style="color: #ff0000;">'MySQLConfig.php'</span>;
<span style="color: #b1b100;">require_once</span> <span style="color: #ff0000;">'MySQLBackup.php'</span>;
&nbsp;
<span style="color: #808080; font-style: italic;">// add some databases to backup</span>
<span style="color: #808080; font-style: italic;">// the domain will be appended to the email subject and is also included within the sql file for identification.</span>
<span style="color: #0000ff;">$cfgHost0</span> = <span style="color: #000000; font-weight: bold;">new</span> MySQLConfig<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'username0'</span>, <span style="color: #ff0000;">'password0'</span>, <span style="color: #ff0000;">'database_name0'</span>, <span style="color: #ff0000;">'domain0'</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #0000ff;">$cfgHost1</span> = <span style="color: #000000; font-weight: bold;">new</span> MySQLConfig<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'username1'</span>, <span style="color: #ff0000;">'password1'</span>, <span style="color: #ff0000;">'database_name1'</span>, <span style="color: #ff0000;">'domain1'</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #0000ff;">$backup</span> = <span style="color: #000000; font-weight: bold;">new</span> MySQLBackup<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #808080; font-style: italic;">// the path to the directory where this script is resided</span>
<span style="color: #0000ff;">$backup</span>-&amp;gt;setExecutionPath<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'/srv/domain/backup/'</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #808080; font-style: italic;">// add the database configs to backup</span>
<span style="color: #0000ff;">$backup</span>-&amp;gt;addDatabaseToBackup<span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$cfgHost0</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #0000ff;">$backup</span>-&amp;gt;addDatabaseToBackup<span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$cfgHost1</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #808080; font-style: italic;">// the sender of the backup mail</span>
<span style="color: #0000ff;">$backup</span>-&amp;gt;setSender<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'admin@yourdomain.com'</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #808080; font-style: italic;">// add some people to receive the backup</span>
<span style="color: #0000ff;">$backup</span>-&amp;gt;addRecipient<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'john@yourdomain.com'</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #0000ff;">$backup</span>-&amp;gt;addRecipient<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'frank@yourdomain.com'</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #808080; font-style: italic;">// execute the whole thing</span>
<span style="color: #0000ff;">$backup</span>-&amp;gt;backup<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;</pre>
<p>Falls es Probleme und/oder Anregungen gibt, bitte diesen Post kommentieren, danke!</p>
<p>PS: zum Anlegen eine Cronjobs per SSH auf deinem Server einloggen, dann "crontab -e" ausführen, dann z.B. "0 2 * * 0,3 wget http://yourdomain.com/backup/backup.php -nc -q -O /dev/null" für eine Ausführung Sonntags und Mittwochs um 2 Uhr nachts einfügen. Mit ":wq" speichern und die Datei schliessen, dann sollte es schon funktionieren <img src='http://www.zoe.vc/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<img src="http://feeds.feedburner.com/~r/zoevc/~4/ugf9p2_WC7k" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.zoe.vc/2009/mysql-backup-skript-mit-emailversand/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.zoe.vc/2009/mysql-backup-skript-mit-emailversand/</feedburner:origLink></item>
		<item>
		<title>Meine Top3-Entwicklungstools</title>
		<link>http://feedproxy.google.com/~r/zoevc/~3/v_ZMZThkFN0/</link>
		<comments>http://www.zoe.vc/2009/meine-top3-entwicklungstools/#comments</comments>
		<pubDate>Thu, 28 May 2009 18:15:42 +0000</pubDate>
		<dc:creator>Alex (zoe.vc)</dc:creator>
				<category><![CDATA[Common]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.zoe.vc/?p=67</guid>
		<description><![CDATA[Blog-Parade! Das Ziel, ausgerufen von MSDN Deutschland, ist dabei heute, seine Lieblings-Entwickler-Tools vorzustellen. Da will ich sogleich starten: Platz 3 nimmt das XAMPP Projekt ein. Mit dieser tollen Sammlung bekommt man alles, was man braucht, um lokal mehr oder minder schöne Webseiten zu entwickeln: Webserver, Datenbank und Emailversendeding. Und man kann es überall mit hin [...]]]></description>
			<content:encoded><![CDATA[<p>Blog-Parade! Das Ziel, ausgerufen von <a href="http://blogs.msdn.com/softwarehersteller/archive/2009/05/06/msdn-blog-parade-was-sind-ihre-lieblings-entwickler-tools-mitmachen-und-gewinnen.aspx">MSDN Deutschland</a>, ist dabei heute, seine Lieblings-Entwickler-Tools vorzustellen. Da will ich sogleich starten:</p>
<p>Platz 3 nimmt das XAMPP Projekt ein. Mit dieser tollen Sammlung bekommt man alles, was man braucht, um lokal mehr oder minder schöne Webseiten zu entwickeln: Webserver, Datenbank und Emailversendeding. Und man kann es überall mit hin nehmen, z.B. auf den USB Stick.<br />
In der goldenen Mitte steht SVN, die Open-Source-Lösung zur Softwareversionierung. Da ich ja ein alter Windows-Hase bin, nutze ich VisualSVN, den meiner Meinung nach besten und schönsten SVN-Server für Windows, und TortoiseSVN als Client. SVN hat mir schon mehrfach den Arsch gerettet, zum Glück committe ich immer relativ häfig. Auch unverzichtbar beim Entwickeln von TYPO3-Extensions.<br />
Platz Numero Uno nimmt eindeutig die Eclipse IDE bei mir ein. Ohne dieses wertvolle Tool entsteht eigentlich keine Zeile Code. Die Vorteile liegen auf der Hand: kostet nix, zuverlässig, schier unendlich erweiterbar. Ich nutze dabei das Bundle "Eclipse IDE für Java EE Developers", welches zusätzlich mit PDT, Subclipse und dem Google Appengine SDK gepimpt ist. Damit ist eigentlich alles, was ich so programmiere, abgedeckt.</p>
<p>Ich könnte noch ein wenig weiter auflisten, aber das ist jetzt nicht Sinn der Sache. Also nochmal kurz:</p>
<p>1. Eclipse<br />
2. SVN<br />
3. XAMPP</p>
<p>So, und nun her mit meiner X-BOX!</p>
<img src="http://feeds.feedburner.com/~r/zoevc/~4/v_ZMZThkFN0" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.zoe.vc/2009/meine-top3-entwicklungstools/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.zoe.vc/2009/meine-top3-entwicklungstools/</feedburner:origLink></item>
		<item>
		<title>TYPO3 Performance</title>
		<link>http://feedproxy.google.com/~r/zoevc/~3/n-7erKIraF8/</link>
		<comments>http://www.zoe.vc/2009/typo3-performance/#comments</comments>
		<pubDate>Mon, 23 Mar 2009 16:41:08 +0000</pubDate>
		<dc:creator>Alex (zoe.vc)</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Typo3]]></category>
		<category><![CDATA[nice2know]]></category>
		<category><![CDATA[performance]]></category>

		<guid isPermaLink="false">http://www.zoe.vc/?p=63</guid>
		<description><![CDATA[Im Blog von Dmitry Dulepov stehen einige Dinge über Typo3 Performance, die man sich mal zu Herzen nehmen sollte. #2 war mir bisher noch nicht bekannt.]]></description>
			<content:encoded><![CDATA[<div class="jLanguage">
<ul>
<li><a href="?lan=english"><img alt="english" src="http://www.zoe.vc/wp-content/plugins/jLanguage/icons/en.png" /></a></li>
<li><a href="?lan=german"><img alt="german" src="http://www.zoe.vc/wp-content/plugins/jLanguage/icons/de.png" /></a></li>
</ul>
</div>
<p>Im <a href="http://dmitry-dulepov.com/article/eight-performance-tips-for-your-typo3-web-site.html">Blog von Dmitry Dulepov</a> stehen einige Dinge über Typo3 Performance, die man sich mal zu Herzen nehmen sollte. #2 war mir bisher noch nicht bekannt.</p>
<img src="http://feeds.feedburner.com/~r/zoevc/~4/n-7erKIraF8" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.zoe.vc/2009/typo3-performance/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		<feedburner:origLink>http://www.zoe.vc/2009/typo3-performance/</feedburner:origLink></item>
		<item>
		<title>FE-Plugin bei mehrsprachigem Typo3</title>
		<link>http://feedproxy.google.com/~r/zoevc/~3/MJi0jY411xc/</link>
		<comments>http://www.zoe.vc/2009/fe-plugin-bei-mehrsprachigem-typo3/#comments</comments>
		<pubDate>Fri, 13 Feb 2009 11:26:07 +0000</pubDate>
		<dc:creator>Alex (zoe.vc)</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Scripting Languages]]></category>
		<category><![CDATA[Typo3]]></category>
		<category><![CDATA[frontend]]></category>
		<category><![CDATA[I18n]]></category>
		<category><![CDATA[plugin]]></category>

		<guid isPermaLink="false">http://www.zoe.vc/?p=58</guid>
		<description><![CDATA[Also jedes mal, wenn ich eine mehrsprachige Typo3-Seite erstellen, komme ich durcheinander mit den Sprachen. Und ich vergesse jedes mal, wie man einem Frontend-Plugin sagt, dass es die durch $this-&#62;pi_getLL($key) ausgegebenen Texte lokalisiert. Und das geht so: class tx_extkey_piX extends tslib_pibase { function main() { $this-&#62;sys_language_uid = (int) t3lib_div::_GP('L'); ... } }]]></description>
			<content:encoded><![CDATA[<p>Also jedes mal, wenn ich eine mehrsprachige Typo3-Seite erstellen, komme ich durcheinander mit den Sprachen. Und ich vergesse jedes mal, wie man einem Frontend-Plugin sagt, dass es die durch <em>$this-&gt;pi_getLL($key) </em>ausgegebenen Texte lokalisiert. Und das geht so:</p>
<pre class="php">class tx_extkey_piX extends tslib_pibase {
   function main() {
      $this-&gt;sys_language_uid = (int) t3lib_div::_GP('L');
      ...
   }
}</pre>
<img src="http://feeds.feedburner.com/~r/zoevc/~4/MJi0jY411xc" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.zoe.vc/2009/fe-plugin-bei-mehrsprachigem-typo3/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<feedburner:origLink>http://www.zoe.vc/2009/fe-plugin-bei-mehrsprachigem-typo3/</feedburner:origLink></item>
		<item>
		<title>TYPO3 und UTF-8 mySQL Datenbank</title>
		<link>http://feedproxy.google.com/~r/zoevc/~3/MNgFfAL4KZY/</link>
		<comments>http://www.zoe.vc/2009/typo3-und-utf-8-mysql-datenbank/#comments</comments>
		<pubDate>Mon, 09 Feb 2009 16:01:16 +0000</pubDate>
		<dc:creator>Alex (zoe.vc)</dc:creator>
				<category><![CDATA[Infrastructure]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Typo3]]></category>
		<category><![CDATA[kodierung]]></category>
		<category><![CDATA[kollation]]></category>
		<category><![CDATA[mySQL]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[utf-8]]></category>

		<guid isPermaLink="false">http://www.zoe.vc/?p=46</guid>
		<description><![CDATA[Manchmal ist es nötig, die Datenbank von Typo3 auf UTF-8 umzustellen, da man arabische Zeichen oder was auch immer speichern will, und wobei die Kollation der Datenbank latin1_swedish_ci, mit der sich Typo3 standardmäßig installiert, nicht taugt. Dazu habe ich diesen nützlichen Blogeintrag von Markus Giesen gefunden: Typo3 mySQL-Datenbank auf UTF-8 umstellen bzw. konvertieren Jedoch ist [...]]]></description>
			<content:encoded><![CDATA[<p>Manchmal ist es nötig, die Datenbank von Typo3 auf UTF-8 umzustellen, da man arabische Zeichen oder was auch immer speichern will, und wobei die Kollation der Datenbank <em>latin1_swedish_ci</em>, mit der sich Typo3 standardmäßig installiert, nicht taugt.</p>
<p>Dazu habe ich diesen nützlichen Blogeintrag von Markus Giesen gefunden: <a href="http://blog.markusgiesen.de/2007/07/29/typo3-mysql-datenbank-auf-utf-8-umstellen/">Typo3 mySQL-Datenbank auf UTF-8 umstellen bzw. konvertieren</a></p>
<p>Jedoch ist bei mir im Export nie die Kollation festgeschrieben, diesen Schritt konnte ich de facto überspringen. Auch hatte ich keinen phpMyAdmin, also mussten die Kommandos für die SQL-Konsole zum Anpassen der Kollation her:</p>
<p>Anzeigen der verfügbaren Kollationen auf dem Server:</p>
<pre class="sql"><span style="color: #993333; font-weight: bold;">SHOW</span> COLLATION
<span style="color: #993333; font-weight: bold;">SHOW</span> COLLATION <span style="color: #993333; font-weight: bold;">LIKE</span> <span style="color: #ff0000;">'utf%'</span></pre>
<p>Ändern der Kollation der aktuellen Datenbank:</p>
<pre class="sql"><span style="color: #993333; font-weight: bold;">ALTER</span> <span style="color: #993333; font-weight: bold;">DATABASE</span> <span style="color: #993333; font-weight: bold;">DEFAULT</span> COLLATE utf8_general_ci</pre>
<p>Und danach weiter nach Markus Giesens Anleitung verfahren und alles wird gut <img src='http://www.zoe.vc/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<img src="http://feeds.feedburner.com/~r/zoevc/~4/MNgFfAL4KZY" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.zoe.vc/2009/typo3-und-utf-8-mysql-datenbank/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.zoe.vc/2009/typo3-und-utf-8-mysql-datenbank/</feedburner:origLink></item>
	</channel>
</rss>
