Drupal: From localhost to your domainsite in five steps



The designer in you, has finished to create the plus ultra of web pages, the only problem is that your web pages is in localhost, or worse yet, it is in a subdirectory in another domain. No problem, with this five step guide step you are going to have our web page ready to be truly Online

Step 1
Backup your database and webpage and put it in your new domain. This mean you have to enter your cpanel ( or other web manager , if you have plesk, may Odin be with you) and go to PhpMyAdmin ( you can install it if you dont have one, its free!) and export your database.

Now import it to your new domain. There may be a problem while importing the backup to your new site, If your database backup file is more than 5 mb, then you probably need BigDump. Its an Ajax uploader of databases. So when exporting your sql, mak sure to uncheck the Extended Insert option, it juss mess up BigDump.

In BigDump, make sure to use UTF-8 (or the schema youre using) in his config, this will make you very happy latter.

Exporting your database so bigdump can use it

Step2: Domain URL
So far so good, you need to modify the sites/default/settings.php
. Change the new database access, and the base_url variable (read the instructions there, nothing fancy really). Make sure that you have the right permission of modifyng that file. Usually it will not come with write permission (or chmod 555) . Make it chmod 777 (change is permission to write) and start modifyng. Then change it back to 555 for security sake.

Step3: htaccess
Did you change the permission for settings.php back to 555? Good, then there's a hidden file called .htaccess (notice the dot at the start) that you may need to modifyng. Search for this string # RewriteBase / and remove that # , so it is umcommented. If for some reason you are still at an subdomain you may need to chage it to # RewriteBase /subdomainname

Step 4: Refresh Cache
Now you need to go to http://www.yournewdomainname.com/oldsubdirectory/admin_menu/flush-cache?destination=admin%2Fsettings%2Fsite-information. Notice the red part is your old subdomain. Maybe you will need to remove it, remember that is the name of your old subdirectory (if you used one).

Ste 5: Run Cron
Now go to http://www..yournewdomainname.com/oldsubdirectory/admin/reports/status/run-cron?destination=admin%2Fsettings%2Fsite-information and enter. You are going to run cron. Again maybe you are not going to need that oldsubdirectory part but, just in case it is there.

Then enjoy, Happy New Year from Jeeba!


Yes Please, hack me

So I was doing my usual web surfing, when i managed to run a "secure website". It amazingly scan my PC for troyans and stuff like that. The most beatiful part is when it says that Windows Defender has detected Spyware on my machine.

Windows Defender on my Ubuntu 10.04, using Opera 10. Feeling the sarcasm already?

Its me or PHP is being Javanized?

I dont really like Java, not the languague per se, only her "WEB" stuff, as a PHP developer, PHP has tought me the easy way to create web application. Dont get me wrong, I started programming in Assembler ( i kinda like it, it just make sense!), C, and then C++ with my structures and pointers and memallocs. I started developing enterprice code in JAVA, back then like 8 years ago, i used to do my interfaces in SWT and Swing, yes Desktop Applications. Then one day i decided to learn PHP, like a hobby, I learn it in 8 hours all the necesary stuff including configuring a basic WAMP server. It is so easy!.

¿What about now?
Eight years ahead, my company decided to make a Web application in Java. Damm its so complex, and not in a good way. I mean, all that complexity is just innecesary, but its like fellow Java Developers cant see that complexitiy because they have been brain washed, yes ORM, yes XML for configuring this or that, centralize those files? ha you must be kidding say one of my coworkers, they think its natural to work that hard to spit a checkbox and a commandButton together, something that even when not using a framework its a piece of cake, what a echo can do in a second, i need like 4 classes, one compiler and 3 minutes restarting my server.

The promised futured aeons
And believe me, that complexity, it just keep growing and growing. I heard the reason for this maddness its it just to keep the promise that the maintenance phase of the application in his lifecycle will be easy. How can it be possible?, It just dont make sense!, how putting more complexity in a system is going to make it easier to maintain? What Java Developers needs to comprehend is that LESS IS MORE!, why cant they comprehend this. Maybe its isn't all their fault, after all, Oracle make a lot of investment so you can believe that their products are the best of the best, your boss eat all that cheesse without asking for a different flavor, you must then pay the consequences of a social design pattern, that i call affecionately, the oracle oriented lobbyming.

So PHP is being Javanized, you say
What Drupal taught me is that you dont really need to be crazy about objects , its not the only way to be!.

But after googling identity maps for PHP on google, i just know that we as PHP developers, are being invaded by the Java Way of Live. All the examples for doing identity maps, are just a biased copy of Java. Separating identity maps from data mappers, and creating a ton of more classes just so it can be like the way its implemented normaly in Java. Why cant it be all in just a single class, after all im using the two of them together all the time.

But you can create a Facade Object and unite the two of them, a Java Saviour will say. Nooo hell no, I protest, just mix it all in the same class, make private functions, if you need, and create functions that call those functions that are called togetehr. After all you make a ton of futil getters and setter function, why not put some really useful functions inside it. STOP copying concepts at litteram, and make use of some creativity. Creativity will kill abstraction some day.

Singleton are Evil and other WTF
For example read this article, singletons are evil, they really are making a storm in a glass of water, they can't test a database access singleton, so they want me to use dependancy injection to "solve that problem"? Yes lets put more maneur on the problem, never mind all the instantiation I made before in my code, i will just refactor the hell out of it so i can put a new parameter on the constructor, for real.

They are so blind with their dogmas, they cant see the real problem lays in another realm. Singletons are useful and not using it just because it cant past an unit test, its insanely crazy, we are not programming to pass the unit test, unit test are not out master but our tools.

Maybe its time to change the way I test my singleton i already gave an alternative on the comments), or dont test it at all, its a singleton for god sake!. We tend to forgot that the goal is creating interesting and maintenable software, not appliyng every concept that they sell us, so our software have that "enterprise quality" that will make our brainwashed souls fell safe.

And so it is
And this is only the tip the iceberg, i know PHP is not the best, I am learning Python,just to know his wonders, but i will never freely choose program in Java again for a Web Project.

Just believe my words, in five years "enterprise" will be a pun for complex, boring and , spaguetti like programming, we just started with Struts, now.. Java?

Unite to the Game Development Group!

How you doing my fellow programmers and designers, i invite you to the newly created Game Development group. Its all about of Game Development (in spanish), in every platform imagined. We will try to be a common nexus between spanish speaking developers around the world. Currently Topics of the group are: show us your project, ideas for a game, questions and answers of the community, and of course all new ideas for topics are welcome and encouraged.

Now go Ahead an suscribe to the group, you know you want it ;)

Grupos de Google
Email:

JavaServer Faces Newbie NavigateError


So Im learning JavaServer Faces using netbeans 6.9, Tomcat 6.0 and Java 1.6.0_22; HotSpot(TM) 64-Bit Server VM 17.1-b03 (whatever it is) and i get caught with lots of errors, I kinda like PHP more than Java but work is work.

The Problem
Studying the navigation in Server Faces (you know the XML tags in faces-config.xml) i was having some troubles with a h:commandButton . After clicking that dammed supersubmit button that jsf kindly created for me (hate, hate,
hate those extra markup lines that JSF created automagically , what in god sake is type="text" value="Hola" name="helloForm:j_id_jsp_1546894878_4" suppose to mean?, is like developers where against designers, well i just want to kill some .. ARGGHHH, ok lets continue...)

Well after clicking that stupid submit button, it just doesn't take me to nowhere, and adding more insult to the injury, the widows seems to being charging. Well lets see what tomcat Log have to say:

Yup, nonsense glibberish in bloddy programmer red, an this is like 1% of the total log

From a noobbie point of view, this output scares me to death. I wasnt suppose to "disrespect" JSF at all, but How in earth Im supposse to know what is the error that makes all that messed up crash log get sooo large!?

The Answer
A bloody backslash, yes a boddy backslash like in /welcomeJSF.jsp. It was ahrd for the framework developer to tell me that the address was at least bad formated? And the tutorials didnt say a word about this. geshh . In puting this so it can help another newbie killing himself with jsf. God have mercy on us (and i dont believe in god, for JSF sake)

Quick tips on Drupal hook user



So as you see, Im playing a lot with the hook_user function in Drupal. It has a lot of power, but unfortunately,theres not too much documentation to play with itl. I am going to post some random tips that i learn using the hook user function so this will be an article that would be updated frequently. The tips are for the Drupal 6.X version. Lets begin!

About the hook user function
This is an useful hook function when you need to play around with the users in Drupal, particulary registering users, updating users, validating the info of user and the deletion of user. This function receive four parameters:
  • $op: The operation to perform. Refer to the api to know all the variables
  • &$edit: The values returned from the login/register form. This is a reference to the variable, so be carufull changing values here
  • &$account: The user object on which the operation is being performed. This variable is not always the current active user!, so the global $user is not always equals to $account. For example if you are the superuser and you are registering manually a user called Michael, the $account should be Michael and $user should be the superuser
  • $category The active category of user information being edited. This works only for updating user info.

Tip A: The account variable in $op = validate
I have some problems with this. I was trying to access the name of the account like this $account->name, but it gave me an error saying that the object dont have that field.

When debbuging the variable, I could see the field name with the corresponding value.So what was the problem? Well it appears than when validating the form, the $account variable is an stdClass object, and with those object you cant use the -> operator, you can only access their fields using a sintaxis like associative arrays, so the correct sintaxis in this case is $account['name'] instead of $account->name. Have some fun with this

Tip B: Help, i cant debug hook_user using Drupal for Firebug, or drupal_set_message

The thing with hook_user and many hook in Drupal is that they are called over and over again across different pages.

Drupal for Firebug works putting some hidden html to your footer, so if you try to use it , it will not work. I dont know exactly why this happen but, for example, using firep in the validate $op just wont work.

drupal_set_message is an useful function to send messages to your current Drupal user. But I couldnt make it show a print_r($account) or a var_dump($account), for some strange reason , it just dont work.

The best way to debug your code , appart from using xcode, or Zend debugger, or other professional debug tools, is using the firephp extesion of Firefox. Theres a magic option called persist that save every data ouptputed to firephp, until you delete it manually.


The only problem with firephp is that you have to somehow, integrate it with Drupal. Its not so hard and this useful article will help you install it in a generic PHP program. But remember my word, that Persist Button IS your only friend in Drupal debugging, forget devel or Drupal for firebug module, they just dont have the power!

UPDATE 21 September 2010: Actually Drupal for firebug is an awesome module. After writing this article, as some sort of poetic justice, Firephp started to fail, an in exchange, Drupal for Firebug started to work!. So, i would recommend to use both, just in case, first plug-in Drupal for Firebug, and if it fails then launch Firephp and catch your bug.

Also the devel module as some nice functions for development. And lets not forget the dblog module (formally watchdog, you can found him here admin/reports/dblog). If you see some blank pages maybe going here can help you solve your problems.

Nobody says that being an PyroEntomologist was fun.

Redirect user after login in Drupal

Redirecting users in Drupal is not easy as it seems to be. In this 6.19 version of Drupal, there are some gotchas to have in mind to make a succesfull redirection

The Direct Path : Hooking form_alter
Like the title say, what we need to do is create a hook for the form_alter hook. This hook is usefull for modifyng the form before rendering it (and for a lot of other interesting stuff), and because Mr. login block and Ms. login page (sitemap.com/user) are also forms, we are going to have fun with the hook(er) (bazinga? well, thats a sick joke). Here are the steps for ultimate redirection control:
  1. Create a module: Create two files yeah.info and yeah.module (change yeah for whatever you wish but make sure to remember that key word) and put them inside sites/all/modules/yeah.
  2. Fill yeah.info with this generic code:
    ;
    $Id$
    name = Yeah Redirect
    description = "Redirect your users at login"
    core = 6.x
    package = "Yeah"

    This is just a required file the module need to exist.

  3. Fill yeah.module with this code

    function yeah_form_alter(&$form, $form_state, $form_id){
    if ($form_id == 'user_login' || $form_id == 'user_login_block') {
    $form['#redirect']=array('thepath/you/want.php');}
    }

    Now, let me explain how this works:
    • The first line tell you that you're hooking the hook_form_alter hook (sic). What does this means is that before any form is rendered this function is being called. Notice the three parameters, first one is the variable that hold the form, its an reference (& anyone?) so the changes you make to &form will exist outside this function. Dont worry too much about $form_state. The third one is the id of the form.
    • The second line is an if that we use to capture only the user_login page form (user_login) and the user_login block form.
    • If the form currently on form_alter is a login form, then we are going to modified it, giving the #redirect property the url that we want to go. If you need to pass parameters then use an array, the first one is the path, and the next ones are the parameters



This code should work for all the user login pages. But it will not work for user login blocks...

What the..

Yes, that code will not work for the login block of Drupal. Why? well because, redirect calls the function drupal_goto($url) an that function is going to ignore you if $_REQUEST['destination'] and/or $_REQUEST['edit']['destination'] exist. Why? I dont have a clue, maybe someone in Drupal wants us to be slapped in the face as a price for using this awesome piece of framework ( no sarcasm here, really!, i luuuuuuuuuve Drupal, well except the drupal_goto function).

The Solution
unset($_REQUEST['destination'], $_REQUEST['edit']['destination']);
Insert this after form redirect and youre ready to go!.

Dude, its not working
Well here are some hints if you need more help:
  1. Make sure you activate the module . Duh!
  2. Check that others noncore modules are not using drupal_goto. Drupal_goto is like a header('Location:....) , it will redirect you to another page, and if there is more code to process after calling drupal_goto, it would not be use.
  3. Clear your theme_cache. Even if you have the 'Rebuild the theme registry on every page load.' on, hell just clear all the cache just in case.
Maybe im missing something here but with this easy explanation i think i have covered all that is need to know for redirecting users at login state. Happy Hooking