One thing that has always bothered me when working with Subversion is the inability to easily add a large number of new files to the repository. Subversion does not have an equivalent of ‘git add *’, so we are left to add all of the new files, at best, one folder at a time.
Imagine doing this for a Drupal site that hasn’t been touched in a while and you need to apply security updates for core, along with a large number of modules. You could very easily spend more time typing in all of your ‘svn add …’ commands than getting the updates applied.
Using the following command, you can affect an ‘svn add’ command on every line returned from ‘svn status’ that has a question mark associated it (ie. new to the repository).
svn status | grep "?" | while read f; do svn add $f; done
Hopefully, this should make adding large numbers of new files to Subversion quite a bit easier. Of course, you could always just use git!
Apache Solr / Drupal search performance tip -
A great tip by Davy Van Den Bremt of Drupal Coder on disabling Drupal’s core search indexer when using Apache Solr.
If you spend a fair amount of time creating new Drupal sites and are not using Drush you are missing out! I used to maintain a subversion repository with my most frequently used modules just for this purpose but this was a very tedious, manual task keeping these modules up to date (almost more trouble than it was worth). With Drush Make however, you can just fire it off, and right before your eyes, you will have a brand new directory with the latest versions of all the modules you specified, downloaded and ready to go.
From Drush make’s project page:
Drush make is an extension to drush that can create a ready-to-use drupal site, pulling sources from various locations. It does this by parsing a flat text file (similar to a drupal .info file) and downloading the sources it describes. In practical terms, this means that it is possible to distribute a complicated Drupal distribution as a single text file.
Below is an example Drush make file.
; CORE core = 6.x projects[] = drupal ; MODULES ; acquia projects[admin_menu][subdir] = "acquia" projects[cck][subdir] = "acquia" projects[filefield][subdir] = "acquia" projects[imageapi][subdir] = "acquia" projects[imagecache][subdir] = "acquia" projects[imagefield][subdir] = "acquia" projects[pathauto][subdir] = "acquia" projects[token][subdir] = "acquia" projects[views][subdir] = "acquia" projects[webform][subdir] = "acquia" ; administration projects[password_strength][subdir] = "other" projects[userprotect][subdir] = "other" ; development projects[coder][subdir] = "other" projects[devel][subdir] = "other" ; THEMES projects[zen][subdir] = "other"
I have shown the example above to illustrate the make file syntax. This example is a bit more lean, module-wise, then even my bare bones make file is. I have separated out the modules contained in the Acquia distribution, of which I am a big fan of, but this is just for organization’s sake.
Once you have created the make file that you are going to use you can implement it with the following command:
drush make "path_to_make_file" /path_to_newsite_/
I have published a standard and a bare-bones make file on GitHub. Please feel free to fork with your changes/additions!
Links of note:
We all know and love Drupal Views. The queries that it builds are most often very elegant, but there are certain cases where you need to use a query that is just a bit too complicated for the Views query generator to build on its own. I ran into this recently where I could not accomplish my task without a join to a sub-query.
If you find this to be the case, you can utilize the views_pre_execute hook to override the query being supplied by Views.
function hook_views_pre_execute(&$view) { if($view->name == 'your_views_name') { $view->build_info['query'] = "SELECT * FROM node" } }
Once you have implemented this in your custom module, if you edit the view on your site, any changes you make that would normally change the query (sort criteria, filters etc.) will have no affect. However, you can utilize the options in ‘Basic Settings’, ‘Page Settings’ to edit the properties of how/where the view is going to display. When you use the ‘Preview’ button to test your view with various displays, your custom SQL query will be displayed so you can verify that it is being used.
Note: You could just create a custom module with custom sql in lieu of using a view. However, if you have already built a view and styled your page/block based on the views generated elements you might not be looking forward to this. In this case you could use the above technique to override the query without disrupting the rest of the work you have done relying on the view.
[video]
[video]
Updated Florida Gators 2010 Football Calendar -
I have updated my Florida Gators Football calendar for the 2010 season. If you add this calendar as a subscription in any calendaring program that supports the iCal standard (iCal, Google Calendar, Outlook, etc) it will update itself on a regular basis with game times and channels when these become available! Florida Gators 2010 Football Calendar.
If you own more than one domain but point them all to the same site, a portion of your virtual host file may look something like this:
<VirtualHost *:80>
ServerName maindomain.com
ServerAlias www.maindomain.com alternatedomain.com
</VirtualHost>
The problem here is that Google sees the same content being served on multiple domains and will knock down your search ranking as a result. The way to remedy the situation is to utilize Apache’s mod_rewrite so that a 301 request pushes the user to your main url. The only caveat being that no matter which domain you type into the browser url bar, it will then be rewritten to the main domain. Here is an example of the code below that you can add to your virtual host file:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www.maindomain.com|alternatedomain.com) [NC]
RewriteRule ^(.*)$ http://maindomain.com$1 [R=301,L]
Save the file, restart Apache, and your alternate domains should then be rewritten to your main domain, your Google ranking preserved, and all is right with the world.
[video]
I use TextMate a lot when doing web development, and I absolutely love it. Some of my friends and colleagues also use TextMate, and I get questions like “what was that thing you did with the thing with the text” sometimes. Here, I thought I would document some of the ones I use most frequently.
Creating tag pairs
To create a tag without having to type those pesky angle-brackets and other thingamabobs, there are a few ways to go about it. First, if you find that you already opened the tag “manually”, you can always close a tag by pressing ⌘ (cmd), ⌥ (alt) and “.”. Secondly, you can open a pair of opening and closing tags by using ctrl and “<”. That gives you a default tag of “<p></p>”, which you can then either just change into whatever you want by typing the tag name, and the closing tag automatically changes, or you can tab into the middle if you’re happy with creating a p-tag (same goes for when you have changed it, press tab to jump into the tag).
This way of creating a tag pair allows you to type in attributes before tabbing into creating the content of the element. There is a second way to use this command, and that is to type the name of the tag first (like for instance “li”) and then hit ctrl and “<”, that will give you opening and closing tags and the cursor placed inside straight away.
If you already have a piece of content (a line of text or other HTML elements) that you need to wrap in a pair of tags, you can use ctrl, ⇧ (shift) and “w”. Too bad it doesn’t reindent your code for you, but you can’t win all the time…
Working with selections
Speaking of wrapping stuff, one really useful command when wrapping text with “<a>”-tags is to use ctrl, ⇧(shift) and “L”. That means the text you selected becomes a link, and as an added bonus, the contents of your clipboard gets inserted as the value of the href-attribute. Pretty handy, eh? When I create dummy links on a page, I just copy a hash-character (#) and then just zoom through the text, adding links where necessary. You can also use the same command without selecting text, which gives you an empty “<a>”-tag, then just tab into entering the link text when you’re done with the attributes.
TextMate also has the lovely quality of being able to select text over specific columns as well as multiple lines. This means you can make a selection of a specific part of multiple lines and enter text into this spot on all lines, simultaneously. The easiest way of doing this is to hold the ⌥ (alt) key while selecting an area with the mouse. Try creating a few lines of empty space, select a column across all lines and type “<li><a href=”#”>List item</a></li>” - Hey presto, a list with multiple dummy items in one fell swoop! If you’re not a mouse user, you can enter this multiple-row-editing mode by creating a few empty lines, selecting them (by holding ⇧ (shift) and using the arrow keys) and then pressing ⌘ (cmd) + ⌥ (alt) + “a”.
Element specific stuff
There’s also an abunance of element-specific commands to use. When creating a new HTML document, you can either use one of the templates that ship with TextMate, but if you prefer to do everything “by hand”, try typing for example “doctype” followed by pressing tab (and then hit the number key for the option you want), or why not “head” + tab? There are too many of these to go through, but apart from the above mentioned “doctype” and “head” shortcuts, try tabbing after typing “form” or “table”. That gives you some default scaffolding instead of the tedious work of typing out everything in these elements by hand.
You don’t do the math
When editing CSS, I don’t use as many shortcuts, I find that they mostly slow me down. A couple of things worth noting is that most properties can be tab-completed, if you’re unsure of spelling or syntax. Try typing “background” followed by a tab, for example: that will give you a couple of choices for background properties.
One thing that is quite handy, though, is the built in math bundle: you can do calculations of measurements inline! Say that you’re trying to calculate the em-size of a particular piece of text, and you want it to harmonize with the vertical rythm of the page. You need a line height of 18px for text set in 14px, in ems. Just type “line-height: 18/14em;”, select the “18/14” part and press ctrl + ⇧ + “C”, which gives you a couple of options for calculating a value. Choose “evaluate and replace expression” (no. 2) and you’re good to go!
Finally, it’s also worth mentioning in this context that all of the defaults for what happens for a specific command is easily customized via Bundle Editor, accessed via Bundles - Bundle Editor - Show Bundle Editor (there’s even a keyboard shortcut for that: ⌘ + ⌥ + ctrl + “B”).
Happy coding!