SSH: Backup all databases

You can dump all the databases into a single .sql file like so:

mysqldump --all-databases > database_backup.sql

Or you can dump them individually to a directory with the date of backup to /home/ by using a for loop, such as this:

now=$(date +"%m_%d_%Y");mkdir /home/mysql.back.$now && for i in $(mysql -BNe 'show databases'| grep -v _schema);do echo $i; sudo mysqldump $i > /home/mysql.back.$now/$i.sql ; done 

Split and merge large files

Use the split command to do this:

split --bytes=1024m bigfile.iso small_file_

That command will split bigfile.iso into files that are 1024 MB in size (1GB) and name the various parts small_file_aa, small_file_ab, etc. You can specify b for bytes, k for Kilobytes and m for Megabytes to specify sizes.

To join the files back together on Linux:

cat small_file_* > joined_file.iso

Similarly to join the split files on a Windows machine, use the copy command:

copy /b small_file_* joined_file.iso

Source:
http://linuxpoison.blogspot.com/2008/09/split-and-merge-large-files.html

Cakephp 2.0 default hash type

The default hash type of Cakephp 2.0 is sha1. But when you have set a Security.Salt in the core.php this will be added before your password and before the encryption is done.

To generate a password with Salt you can either create an User::add method in Cakephp and use the Authcomponent or create some your own. I needed it for fast checking user accounts with a javascript frontend (no views are used).

// Your salt from core.php
// Configure::write('Security.salt', 'e4ac429040b9d4552bc425b677b64aca104c5f84f');
$salt = 'e4ac429040b9d4552bc425b677b64aca104c5f84f';
$yourpassword = 'mysecret';
 
$password = sha1($salt.$yourpassword);
// The password to use in Cakephp with the Authcomponent
print $password;

Thats all, you use that password in your mysql admin tool to create users on the fly.

Source

Magento: How to Upgrade Magento community to 1.8

How to Upgrade Magento community to 1.8

How to Upgrade Magento community to 1.8

Magento recommends you upgrade your installation using the following guidelines in a development or test environment, separate from your existing production environment:

  1. Create a parallel development or testing system, identical to your current production system.
    You’ll use this parallel system to implement and test the Magento upgrade.
  2. In your current production environment:
    1. Back up your Magento database.
    2. Archive the file system.
      This includes the media directory and subdirectories; all extensions and customizations; and all custom themes.
  3. In the development or test environment:
    1. Create a new, empty database instance.
    2. Import the production database tables into the development database instance.
    3. Copy your production media directory, extensions, themes, and other customizations to the development system.
    4. Copy local.xml to magento-install-dir/app/etc and edit it if necessary to reference the production database instance.
    5. In a web browser, go to your development system base URL.
    6. Wait for upgrade scripts to run.
    7. Verify the development system is now identical to the production system.
      If not, fix issues, retest, and upgrade again.
  4. Test the development system thoroughly, including:
    • Verify all extensions, themes, and customizations work.
    • Place orders using all webstores and all payment methods.

Htaccess: how to force “www.” in a generic way?

This works on any domain

#Remove the below two comments to disable it on localhost
#RewriteCond %{HTTP_HOST} !=localhost
#RewriteCond %{HTTP_HOST} !=127.0.0.1
RewriteCond %{HTTP_HOST} !^$
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

PHP: CHMOD a directory recursively

The script below loops over the specified directory and chmods its files, directories and subdirectories recursively.

<?php

  function chmodDirectory( $path = '.', $level = 0 ){  
  $ignore = array( 'cgi-bin', '.', '..' ); 
  $dh = @opendir( $path ); 
  while( false !== ( $file = readdir( $dh ) ) ){ // Loop through the directory 
  if( !in_array( $file, $ignore ) ){

        if( is_dir( "$path/$file" ) ){

          chmod("$path/$file",0755);

          chmodDirectory( "$path/$file", ($level+1));

        } else {

          chmod("path/$file",0644); // desired permission settings

        }//elseif 
	}//if in array 
	}//while 
	
	closedir( $dh ); 
	}//function
	chmodDirectory("the_directory/",0);

?> 

Magento: Move a category programmatically

It turns out that Magento has some really convenient functions already made at its core, which i don’t know about and this is one of them. Mage category model object includes move() function, that manages just that. Lets view simple code example for better understanding.

$categoryId = 2269;
$parentId = 2268;

$category = Mage::getModel('catalog/category')->load($categoryId);
$category->move($parentId, null);

When this is executed your category should have a different path, if changes are not visible than try to clean cache and reindex data. After you have done that everything should be ok.

Page 2 of 241234567»

Pin It on Pinterest