CiviCRM Community Forums (archive)

*

News:

Have a question about CiviCRM?
Get it answered quickly at the new
CiviCRM Stack Exchange Q+A site

This forum was archived on 25 November 2017. Learn more.
How to get involved.
What to do if you think you've found a bug.



  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Installing CiviCRM »
  • Drupal Installations (Moderator: Piotr Szotkowski) »
  • Smarty + safe mode
Pages: [1]

Author Topic: Smarty + safe mode  (Read 21932 times)

arlind

  • Guest
Smarty + safe mode
May 08, 2008, 02:49:34 pm
Hi

Smarty works fine until one of its temp-directories gets replaced with a new one with the wrong owner and chmod settings - as if it is deleted and created as new.

Smarty says it does not replace any diretories, and it only happens on CiviCRM settings pages (not on normal pages).

Does CiviCRM try to re-install the Smarty diretories?

from smarty support:
http://www.phpinsider.com/smarty-forum/viewtopic.php?t=13234

from CiviCRM support:
http://forum.civicrm.org/index.php/topic,2821.0.html

thanks Bo

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: Smarty + safe mode
May 08, 2008, 07:21:23 pm

I'd like to avoid playing the "we do this, they do that" game, since it does not really solve your problem.

Your best bet would be to get into the codebase and figure out when directories are being created etc. Most / all of our directories are created via CRM/Utils/File.php, function createDir. You can put a debug statement in there and try to figure out the offending functions. You might also want to print a backtrace (CRM_Core_Error::backtrace( ) )

Either CiviCRM or Smarty seems to not do the right thing at a certain page. the above might make things a bit more clear and give us some more clues.

lobo
A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

arlind

  • Guest
Re: Smarty + safe mode
May 10, 2008, 11:29:57 am
Quote from: Donald Lobo on May 08, 2008, 07:21:23 pm
Most / all of our directories are created via CRM/Utils/File.php, function createDir. You can put a debug statement in there and try to figure out the offending functions. You might also want to print a backtrace (CRM_Core_Error::backtrace( ) )

It works!!! I have disabled these two functions, and CiviCRM are now runing without any Smarty errors.

Code: [Select]
    /**
     * create a directory given a path name, creates parent directories
     * if needed
     *
     * @param string $path  the path name
     *
     * @return void
     * @access public
     * @static
     */
    function createDir( $path ) {
        if ( is_dir( $path ) || empty( $path ) ) {
            return;
        }

        CRM_Utils_File::createDir( dirname( $path ) );
        #if ( mkdir( $path, 0777 ) == false ) {
        #    echo "Error: Could not create directory: $path.<p>If you have moved your database from a development install to a production install and the direcotory paths are different, please set the column config_backend in the civicrm_domain table to NULL. You will need to reinitialize your settings in the production install.<p>";
        #    exit( );
        #}

    }

    /**
     * delete a directory given a path name, delete children directories
     * and files if needed
     *
     * @param string $path  the path name
     *
     * @return void
     * @access public
     * @static
     */
    public function cleanDir( $target ) {
        static $exceptions = array( '.', '..' );

        if ( $sourcedir = @opendir( $target ) ) {
            while ( false !== ( $sibling = readdir( $sourcedir ) ) ) {
                if ( ! in_array( $sibling, $exceptions ) ) {
                    $object = $target . DIRECTORY_SEPARATOR . $sibling;

                    if ( is_dir( $object ) ) {
                        CRM_Utils_File::cleanDir( $object );
                    } else if ( is_file( $object ) ) {
                        #$result = @unlink( $object );
                    }
                }
            }
            closedir( $sourcedir );
            #$result = @rmdir( $target );
        }
    }

I do not know anything about backtrace - so what can I do to help to figure out why CiviCRM replaces Smartys temp-dir?

Somehow php can't set the chmod settings with mkdir( $path, 0777 ) on my server, but need to have a chmod() call afterwards (Smarty does this). But still the Smarty-directory should not be deleted in the first place :-)

Thanks for Your help
Bo :-)

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: Smarty + safe mode
May 10, 2008, 11:36:47 am

it does work now, but i'm not sure if it will work properly going forward. If those functions dont return an error message, we assume those directories are created etc, this might result in other errors not being trapped in other parts of the code

lobo
A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

arlind

  • Guest
Re: Smarty + safe mode
May 10, 2008, 12:39:35 pm
hmm... I have changed the code so only rmdir() is disabled in cleanDir, and it still works. When I enable rmdir(), Smarty stops working.

On my server the directories must have my user as owner and chmod 777, before php can write files into it. The owner can only be set manually via FTP. Thus Smarty can not write files in the new directory.

I guess Smarty saves to many temp-files over time, and that is why CiviCRM deletes the directory. But to avoid this error on similar servers, CiviCRM should only delete the files - not the directory.

Second on my server mkdir() does not set the chmod settings, it must be set through a call to the chmod() function afterwards. Smarty does this to prevent errors.

These are two small changes I would like to suggest to CiviCRM :-)

Thanks
Bo

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Installing CiviCRM »
  • Drupal Installations (Moderator: Piotr Szotkowski) »
  • Smarty + safe mode

This forum was archived on 2017-11-26.