Monday, October 5, 2009

Drupal unable to login due to crashed MYSQL table

For no apparent reason, our Drupal site refused to allow a regular login. The site itself seems to be working fine - but attempts to login into administration simply do not work and are redirected to the homepage.

(caveat: perhaps I've managed to hide some status/error messages being displayed in the process as I've changed quite a few things when it comes to the template files used).

Either way, I've ended-up looking in the watchdog table where I noticed the following most recent entries all the way at the bottom:
Table '.\database-name\sessions' is marked as crashed and should be repaired
query: INSERT INTO sessions
(sid, uid, cache, hostname, session, timestamp)
VALUES (....)
Seems like MYSQL table sessions is marked as crashed! Kind of makes sense why we're not able to login - new sessions are probably not being created due to the table crash.

Google quickly points to the REPAIR TABLE syntax for MYSQL which luckily runs without issues and we're back online being able to login again!

If that did not work? Probably delete and re-create the sessions table I guess.

Wednesday, June 24, 2009

Drupal Zen theme

My latest Drupal-based website is going to be based on the Zen theme. What a joy! If only I had discovered it earlier. Really simplifies things and makes the theme come to life quicker. At least for now it is (1st day of serious development work). So if you're clicking around finding a Drupal 5.x theme, might as well try Zen first.

Incidentally, I've stumbled upon the and its 960 grid system which looks fantastic for future work. Loved the way the grid is defined and controlled. Dead simple, works without hassle across browsers.

Oh. And I hope to finally start using reset.css as a standard way of "equalizing" browser behavior. 960 ship their code with reset.css based on (I think) Eric Meyer's original reset (or was it Dave Shea?). Life is great.

Drupal 6 and Panels

As I was starting out work on a new website to be implemented in Drupal, I was finally getting around the idea of using version 6 that everyone seems to be happily using for many months now.

My typical usage of Drupal consists of heavily relying on Panels and Views to pull-off the website's structure. It was somewhat of a shock to discover that Panels 2 is sort of abandoned in favor of Panels 3 for Drupal 6. That would be fine if it wasn't for the fact that Panels 3 is really still in heavy development. After several attempts to try and use it (followed by a patch from the 'dev' branch) I realized that I might end-up having a bit too many issues with Panels 3 to try and deploy it for this project. And since I still can't figure out what do people use if they're not using Panels to pull-off complicated structures I decided to go back to Drupal 5. Sigh. Sadly.

Wednesday, June 17, 2009

Switching to Mac

Very excited with my new MacBook Pro.

However, two steps forward one step back: I have a Rails application that reads MS Excel files via win32ole Ruby library. In Mac OS X that does not work and I now have effectively no way to run the application on my Mac until completely re-coding the part that deals with Excel! What a disaster.

Have found info suggesting the use of OpenOffice which should work on both OS X and Windows but that still is going to require coding time. *sigh*

C# UserControl not displayed in toolbox

Weirdest thing.

If you create a C# (VS2005) UserControl, ineriting UserControl and implement an interface that is defined in the same project in which the user control resides your toolbox will happily show your control. In addition, you can add it to various forms you may have. Everything is as expected.

However, if you attempt to implement an interface defined in a separate project (class library) referenced by the project where the user control resides everything falls apart. Forms that have been showing the user control will not load their designer and the user control tends to disappear from the toolbox.

I have no idea why this is so.

Thursday, April 9, 2009

Rails ActiveRecord update and Ruby Observable update in conflict?

In a recent project I've tried using Ruby's Observable module (from the Ruby standard library).I've created a Donation class (the subject) and a DonationObserver (the observer). 

As per the definition DonationObserver is supposed to provide a method called update to participate in the observer pattern. In my case, it had 2 parameters.

I also wanted to save these observers into the database and load them on demand. Hence, DonationObserver extended ActiveRecord::Base (it was one of my model classes).

Everytime an attempt is made to update (into the database) the runtime resolves that call to the update method defined for the purpose of the Observer pattern (in my DonationObserver). This produces a large stack trace complaining "wrong number of arguments (0 for 2)" and pointing all the way to line 2483 in base.rb where it says:
def create_or_update
raise ReadOnlyRecord if readonly?
result = new_record? ? create : update # line 2483 in base.rb
result != false
In other words, it appears that being the observer and an active record instance simply will not work together without some hacks. Perhaps I'd need to override the Observable's notify_observer method and call a different method in the target observer from the default update.

Am I missing something?

Well, a quick and dirty way out of this is to just simply override the add_observer and notify_observers methods from observer.rb. You'll need to change the:
unless observer.respond_to? :update
to checking for any other method you're going to use:
unless observer.respond_to? :update_observer
Similarly, change the notify_observers from:
for i in @observer_peers.dup
for i in @observer_peers.dup
And finally, the observer class (DonationObserver) would get a new method called update_observer(...) with some appropriate arguments. 

Thursday, January 22, 2009

Configuring IIS and Apache to work with multiple IPs

This is a small tip regarding configuration of IIS and Apache to co-exist on the same box listening on port 80 for HTTP traffic on different IPs.

My initial setup had Win Server 2003 with IIS 6.0 serving all domains. Incidentally, there were several different domains all pointing to the same IP address and having IIS configured to bind to All Unassigned IPs across them all.

With the introduction of Apache, I was given a new IP address and wanted to have it used by Apache alone. Turns out that IIS would auto-bind to the new address due to its All Unassigned IPs rule in the configuration. The trick to fix that is to configure IIS' IP listen list. Read the MSDN article about it or just run (via command line): httpcfg.exe set iplisten -i x.x.x.x

Restarting IIS after that is not enough (as advised by the article). I would still get apache reporting: An attempt was made to access a socket in a way forbidden by its access permissions.  : make_sock: could not bind to address x.x.x.x. 

The trick? Reboot the server. Then apache manages to listen to the 2nd address normally.

Monday, January 19, 2009

Translating a Drupal Website

And after many many months of procrastrination and delaying, I'm cornered into doing a Drupal website translation into the 2nd language. In my case, the main site is in bosnian and we're adding an english version to it.

My current understanding of the entire process suggests that I'll end up doing quite a lot of duplication of view and block definitions and even panel 2 definitions. That's just something I hate and therefore have been shying away from. I say that this is *my* current understanding and hence may be wrong (which I suspect is the case).

This post will document the process, questions, thoughts, etc - things I hope will be useful to someone else doing a similar translation.


First of all, I'll explain how the current site is organized. 90% of the site runs through Panels 2. I'm using plenty of Views and there are custom content types via CCK. For example, we have Author, Company and Text content types. Text uses Author reference in one of its drop-downs (in this case the author is often someone else from where the article was obtained; the person entering the article into drupal is one of the few admin writers).

There are many Views used everywhere. A common view definition for filters would be:
- node published = YES
- Author node reference = EDITORIAL TEAM Author
- etc.

The biggest problem so far is whenever I have a view that references an author node (the "editorial team" above) that automatically means that:
- Must translate the bosnian version of Editorial Team into its english equivalent (eg. Editorial Team ENG)
- I must create a duplicate view and redefine the filter to use Author node reference = Editorial Team Eng (after switching manually the edit view URL to .../en/.... from .../bs/... so that the english author appears in the filter drop-down)

This is quite a pain and super-demotivating. I can't help but think that I've made some bad choices somewhere or am doing something wrong entirely to be forced to do these duplications.

(to be continued).