Code snippets for symfony 1.x

Navigation

Refine Tags

Snippets tagged "bash"

script for to generate (all) modules

This Bash script transform: 'BaseModel.class.php' => 'BaseModel' => 'Model' then call doctrine:generate-admin frontend 'Model', for all files from lib/model/doctrine/base.

#!/bin/bash
for file_class in `ls lib/model/doctrine/base`  do
    base_model=${file_class/%.class.php/}      
    model=${base_model/#Base/}                 
    ./symfony doctrine:generate-admin --env="prod" frontend $model
done
 
by Vlad Bazon on 2010-08-01, tagged bash  doctrine  generateadmin  model  modul  symfony 

Automatically create symlinks to plugins' web directories

I use this small bash script to automatically detect /plugins/*/web directories and symlink them in /web folder.

This is particularly useful for SVN installations of plugins, which do not handle this for you.

#!/bin/bash
 
if [ ! -d web -o ! -d plugins ]
then
  echo "You must be in a Symfony project root"
  exit 1
fi
 
# Create links from /web directory
cd web
 
# List plugins' web directories
ls -d "../plugins/*/web" | while read plugin_web
do
  plugin=$(basename $(dirname $plugin_web))
  if [ ! -d $plugin ]
  then
    ln -f -s -v $plugin_web $plugin
  fi
done
 
# Go back to project's root
cd ..
 

You could use a "compact" version as an alias ;)

alias ln_plugins_web="cd web && ls ../plugins/*/web | while read plugin_web; do plugin=$(basename $(dirname $plugin_web)); if [ ! -d $plugin ]; then ln -f -s -v $plugin_web $plugin; fi; done; cd .."
 

Note : if your bash installation does not provide "basename" and "dirname" commands, you can add them manually with those aliases

function dirname() {
  echo "$1" | sed 's/\/[^\/]*\(\/*\)\?$//';
}
 
function basename() {
  echo "$1" | sed 's/^.*\/\([^\/]\+\)\/*$/\1/
}
by Nicolas Chambrier on 2008-03-23, tagged bash  linux  plugins  web 

Bash script to init a subversionned Symfony project

I share here the script I use to initialize a new Symfony project, as I always subversion them.

This script handles the following default scenario :

You can customize the behaviour of the script defining environment variables. This is an unusual way to do, but it has two advantages :

Here is what you can change in the default scenario :

Here is what is always done, and the really goal of this script (to simplify your life) :

Full usage :

Usage : new-symfony-project PROJECT-NAME
You can define following variables to customize the creation :
- SYMFONY_BRANCH : The Symfony branch used
- SYMFONY_REPOS : The full Symfony SVN repository URL, if set, SYMFONY_BRANCH is ignored
- SYMFONY_DATA : The path to the data folder of your Symfony installation. If not left
  empty, no SVN version will be downloaded (using local installation) and two precedent
  variables will be ignored
- TRUNK_URL : The trunk of your project (default : repos created)
- SVNADMIN_REPOS : Local root for SVN repositories
- WEB_DIR : Local root for Web directories
 

Examples :

  # Start a new project using default options
$ new-symfont-project MyProject
  # Start a new project embedding 1.1 Symfony branch
$ SYMFONY_BRANCH=1.1 new-symfont-project MyProject
  # Start a new project embedding 1.1 Symfony branch and versionned in a remote repository (already initialized)
$ SYMFONY_BRANCH=1.1 TRUNK_URL=my-svn-host/my-svn-repos/trunk new-symfont-project MyProject
  # Start a new project using system-wide install
$ SYMFONY_DATA=/usr/share/php/data new-symfont-project MyProject
 

Here is the code, you must customize the first 5 lines to fit your default environment options :

#!/bin/bash
 
DEFAULT_WEB_DIR=/home/naholyr/www
DEFAULT_SVNADMIN_REPOS=/home/naholyr/svn
DEFAULT_SYMFONY_BRANCH=1.0
 
 
PROJECT=$1
 
 
if [ "$PROJECT" = "" ]; then
  # Show help and exit
  echo "Usage : new-symfony-project PROJECT-NAME"
  echo "You can define following variables to customize the creation :"
  echo "- SYMFONY_BRANCH : The Symfony branch used (default : $DEFAULT_SYMFONY_BRANCH)"
  echo "- SYMFONY_REPOS : The full Symfony SVN repository URL, if set, SYMFONY_BRANCH is ignored"
  echo "- SYMFONY_DATA : The path to the data folder of your Symfony installation. If not left"
  echo "  empty, no SVN version will be downloaded (using local installation) and two precedent"
  echo "  variables will be ignored"
  echo "- TRUNK_URL : The trunk of your project (default : repos created)"
  echo "- SVNADMIN_REPOS : Local root for SVN repositories (default : $DEFAULT_SVNADMIN_REPOS)"
  echo "- WEB_DIR : Local root for Web directories (default : $DEFAULT_WEB_DIR)"
fi
 
 
if [ "$SVNADMIN_REPOS" = "" ]; then
  SVNADMIN_REPOS=$DEFAULT_SVNADMIN_REPOS
fi
 
if [ "$WEB_DIR" = "" ]; then
  WEB_DIR=$DEFAULT_WEB_DIR
fi
 
if [ "$SYMFONY_BRANCH" = "" ]; then
  SYMFONY_BRANCH=$DEFAULT_SYMFONY_BRANCH
fi
 
if [ "$SYMFONY_REPOS" = "" ]; then
  SYMFONY_REPOS=http://svn.symfony-project.com/branches/$SYMFONY_BRANCH
fi
 
 
if [ "$TRUNK_URL" = "" ]; then
  SVN_REPOS="file://$SVNADMIN_REPOS"
  SVN_PROJECT=$SVN_REPOS/$PROJECT
  # Create repository
  svnadmin create $SVNADMIN_REPOS/$PROJECT
  svn mkdir -m "Standard structure" $SVN_PROJECT/trunk $SVN_PROJECT/branches $SVN_PROJECT/tags
  svn mkdir -m "Create folder for Symfony" $SVN_PROJECT/trunk/lib $SVN_PROJECT/trunk/lib/vendor
  TRUNK_URL=$SVN_PROJECT/trunk
fi
 
 
# Create web folder
cd $WEB_DIR
svn co $TRUNK_URL $PROJECT
cd $PROJECT
 
if [ "$SYMFONY_DATA" = "" ]; then
  # Download Symfony
  svn propset svn:externals "symfony $SYMFONY_REPOS" lib/vendor
  svn commit -m "External link to Symfony"
  svn update
  SYMFONY_DATA=$(pwd)/lib/vendor/symfony/data
fi
 
# Create Symfony project
$SYMFONY_DATA/bin/symfony init-project $PROJECT
 
# Link to Symfony web elements
ln -s $SYMFONY_DATA/web/sf web/sf
 
# Commit the new project
svn status | grep ^? | sed "s/? *//" | xargs svn add
svn mkdir lib/model/om lib/model/map
svn propset svn:ignore "*" log
svn propset svn:ignore "*" cache
svn propset svn:ignore "*schema-transformed.xml" config
svn propset svn:ignore "lib.model.schema.sql
plugins.*.sql
sqldb.map" data/sql
svn propset svn:ignore "*" lib/model/om
svn propset svn:ignore "*" lib/model/map
svn commit -m "Project initialized"
 
# Conclusion
./symfony -V
echo "Working directory : $WEB_DIR/$PROJECT"
echo "You should be ready to go :)"
 

Note that if you work this way, intensively take advantage of Subversion and install plugins as svn:externals ;)

by Nicolas Chambrier on 2008-02-13, tagged bash  initialize  script  subversion 
(1 comment)

bash alias to cleanup

Just add this to your ~/.bashrc

    alias sfcleanup='symfony propel-build-model && symfony propel-build-sql && symfony propel-insert-sql && php batch/load_data.php && symfony cc'

Next time you want to do a cleanup just type sfcleanup at the project dir.

by Roberto Carvajal on 2006-08-24, tagged bash  cli 
(1 comment)