Supporting each other

Community forums

Welcome, Guest
Username: Password: Remember me
Report any technical problems you discover and discuss solutions.

TOPIC:

Creating Projects - cannot Insert 11 years 3 months ago #473

  • JohnSmith
  • JohnSmith's Avatar
  • Offline
  • Moderator
  • Moderator
  • Posts: 397
  • Thank you received: 71
Hi Tom,

Definitely something with the filesystem at play. This block of code from /modules/xerte/new_template.php
    _debug("Creating new template : $folder_name_id, $parent_template_name");
    $new_path = $xerte_toolkits_site->users_file_area_full . $folder_name_id . "-" . $_SESSION['toolkits_logon_username'] . "-" . $parent_template_name;
    $path = $xerte_toolkits_site->users_file_area_full . $folder_name_id . "-" . $_SESSION['toolkits_logon_username'] . "-" . $parent_template_name;
    if(is_dir($path)) {
        _debug("Trying to create new template at location - $path - it's already in use. Aborting");
        die("Template directory already exists; will not overwrite/re-create.");
    }
    if(mkdir($path)){
        _debug("Created $path ok");
        if(@chmod($path,0777)){
            $ok = copy_r($dir_path, $path);
            _debug("Copy_r returned " . print_r($ok, true));
            return $ok;
        }else{
            _debug("Failed to set rights ");
            receive_message($_SESSION['toolkits_logon_username'], "FILE_SYSTEM", "MAJOR", "Failed to set rights on parent folder for template", "Failed to set rights on parent folder " . $path);
            return false;
        }
    }else{
        receive_message($_SESSION['toolkits_logon_username'], "FILE_SYSTEM", "CRITICAL", "Failed to create parent folder for template", "Failed to create parent folder " . $path);
        return false;
    }

Is failing. You can see the first line "Creating new template : 12, Nottingham" in the logs posted but after that nothing from this block, suggesting that mkdir($path) is failing and the if is falling into the last 'else' which conveniently isn't writing anything to the log...

So there are 2 possible causes here: Either the parent of $path isn't writable... or $path is invalid...

Are periods allowed in Apache/IIS folder names? That's the only possible thing that I could see that could possibly be an issue, 9-chris.walsh-Nottingham, other than permissions... even though it is a long shot...

John

Please Inloggen or Create an account to join the conversation.

Last edit: by JohnSmith.

Creating Projects - cannot Insert 11 years 3 months ago #474

  • tom
  • tom's Avatar
  • Offline
  • Administrator
  • Administrator
  • Posts: 1286
  • Thank you received: 324
<?PHP     /**
* 
* new template page, allows the site to make a new xerte module
*
* @author Patrick Lockley
* @version 1.0
* @copyright Copyright (c) 2008,2009 University of Nottingham
* @package
*/


$temp_dir_path="";
$temp_new_path="";

// taken from php.net/manual/en/function.copy.php

define('DS', DIRECTORY_SEPARATOR); // I always use this short form in my code.

function copy_r( $path, $dest )
{
    if(preg_match('/\.svn/', $path)) {
        _Debug("Skipping .svn dir ($path)");
        return true;
    }
    _debug("Copying $path to $dest, recursively... ");
    
    if( is_dir($path) )
    {
        @mkdir( $dest );
        $objects = scandir($path);
        if( sizeof($objects) > 0 )
        {
            foreach( $objects as $file )
            {
                if( $file == "." || $file == ".." )
                    continue;
                // go on
                if( is_dir( $path.DS.$file ) )
                {
                    copy_r( $path.DS.$file, $dest.DS.$file );
                }
                else
                {
				
					if(strpos($file,".info")===FALSE){
				
						copy( $path.DS.$file, $dest.DS.$file );
						
					}
                }
            }
        }
        return true;
    }
    elseif( is_file($path) )
    {
        return copy($path, $dest);
    }
    else
    {
        return false;
    }
}

/**
 * 
 * Function sort out paramaters
 * This function creates folders needed when duplicating a template
 * @param number $folder_name_id - the id of this template
 * @param number $tutorial_id_from_post - the parent template name for the new tutorial
 * @version 1.0
 * @author Patrick Lockley
 */


function create_new_template($folder_name_id,$parent_template_name){

    global $dir_path, $new_path, $temp_dir_path, $temp_new_path, $xerte_toolkits_site;


    $row_framework = db_query_one("SELECT template_framework from {$xerte_toolkits_site->database_table_prefix}originaltemplatesdetails WHERE template_name = ?", array($parent_template_name));


    // I think this is wrong, currently looking like : /home/david/src/xerteonlinetoolkits/modules//templates/0 should presumably be home/david/src/xerteonlinetoolkits/modules/xerte/templates/Nottingham
    $dir_path = $xerte_toolkits_site->basic_template_path . $row_framework['template_framework'] . "/templates/" . $parent_template_name;

    /**
     * Get the id of the folder we are looking to copy into
     */

    _debug("Creating new template : $folder_name_id, $parent_template_name");
    $new_path = $xerte_toolkits_site->users_file_area_full . $folder_name_id . "-" . $_SESSION['toolkits_logon_username'] . "-" . $parent_template_name;
    $path = $xerte_toolkits_site->users_file_area_full . $folder_name_id . "-" . $_SESSION['toolkits_logon_username'] . "-" . $parent_template_name;
    if(is_dir($path)) {
        _debug("Trying to create new template at location - $path - it's already in use. Aborting");
        die("Template directory already exists; will not overwrite/re-create.");
    }
    if(mkdir($path)){
        _debug("Created $path ok");
        if(@chmod($path,0777)){
            $ok = copy_r($dir_path, $path);
            _debug("Copy_r returned " . print_r($ok, true));
            return $ok;
        }else{
            _debug("Failed to set rights ");
            receive_message($_SESSION['toolkits_logon_username'], "FILE_SYSTEM", "MAJOR", "Failed to set rights on parent folder for template", "Failed to set rights on parent folder " . $path);
            return false;
        }
    }else{
        _debug("Can't create $path");
        receive_message($_SESSION['toolkits_logon_username'], "FILE_SYSTEM", "CRITICAL", "Failed to create parent folder for template", "Failed to create parent folder " . $path);
        return false;
    }
}

Chris, can you please check whether using this file logs an error in debug.log?

It should be in modules/xerte/new_template.php, only line 110 is added.
The following user(s) said Thank You: chris.walsh

Please Inloggen or Create an account to join the conversation.

Last edit: by tom. Reason: Attachments do not work

Creating Projects - cannot Insert 11 years 3 months ago #475

  • tom
  • tom's Avatar
  • Offline
  • Administrator
  • Administrator
  • Posts: 1286
  • Thank you received: 324
Also, can you send me or John the contents of setup/phpinfo.php? Or check the setting of safe_mode?

Reijnders (at) tor.nl

Please Inloggen or Create an account to join the conversation.

Creating Projects - cannot Insert 11 years 3 months ago #476

  • chris.walsh
  • chris.walsh's Avatar Topic Author
  • Offline
  • New Member
  • New Member
  • Posts: 17
  • Thank you received: 0
Hi Tom,

You are correct. The error is logged:
2013-07-29 19:01:17 C:\Apache24\htdocs\zone2.derbylearn.net\moodle\xertetoolkits\modules\xerte\new_template.php91Creating new template : 16, Nottingham
2013-07-29 19:01:17 C:\Apache24\htdocs\zone2.derbylearn.net\moodle\xertetoolkits\modules\xerte\new_template.php110[b]Can't create C:/Apache24/htdocs/zone2.derbylearn.net/moodle/xertetoolkitsUSER-FILES/16-chris.walsh-Nottingham[/b]
2013-07-29 19:01:17 C:\Apache24\htdocs\zone2.derbylearn.net\moodle\xertetoolkits\website_code\php\database_library.php139Running : SELECT * FROM sitedetails
2013-07-29 19:01:17 C:\Apache24\htdocs\zone2.derbylearn.net\moodle\xertetoolkits\website_code\php\database_library.php139Running : SELECT * FROM sitedetails
2013-07-29 19:01:17 C:\Apache24\htdocs\zone2.derbylearn.net\moodle\xertetoolkits\website_code\php\database_library.php139Running : select originaltemplatesdetails.template_name, logindetails.username, originaltemplatesdetails.template_framework, templaterights.user_id, templaterights.folder, templaterights.template_id, templatedetails.access_to_whom from originaltemplatesdetails, templaterights, templatedetails, logindetails where templatedetails.template_type_id = originaltemplatesdetails.template_type_id and templatedetails.creator_id = logindetails.login_id and templaterights.template_id = templatedetails.template_id and templaterights.template_id="16" and role="creator"
2013-07-29 19:01:17 C:\Apache24\htdocs\zone2.derbylearn.net\moodle\xertetoolkits\website_code\php\database_library.php139Running : select * from templaterights where user_id='4' AND template_id = '16'
2013-07-29 19:01:17 C:\Apache24\htdocs\zone2.derbylearn.net\moodle\xertetoolkits\edit.php30Running : UPDATE templatedetails SET date_accessed='2013-07-29' WHERE template_id = '16'
2013-07-29 19:01:17 C:\Apache24\htdocs\zone2.derbylearn.net\moodle\xertetoolkits\website_code\php\database_library.php139Running : select username from logindetails where login_id='4'
2013-07-29 19:01:17 C:\Apache24\htdocs\zone2.derbylearn.net\moodle\xertetoolkits\website_code\php\database_library.php139Running : SELECT * FROM sitedetails
2013-07-29 19:01:23 C:\Apache24\htdocs\zone2.derbylearn.net\moodle\xertetoolkits\website_code\php\database_library.php139Running : SELECT * FROM sitedetails

The log also suggests that a trailing path separator is missing which I can fix in the config.
I think I queried trailing separators early on but then assume safe combining is used simlar to .NET's Path.Combine() function.

Please Inloggen or Create an account to join the conversation.

Creating Projects - cannot Insert 11 years 3 months ago #477

  • JohnSmith
  • JohnSmith's Avatar
  • Offline
  • Moderator
  • Moderator
  • Posts: 397
  • Thank you received: 71
Ah note the missing / before USER_FILES...

You need to log into management.php and edit the path to add a trailing /

John

Please Inloggen or Create an account to join the conversation.

Creating Projects - cannot Insert 11 years 3 months ago #478

  • chris.walsh
  • chris.walsh's Avatar Topic Author
  • Offline
  • New Member
  • New Member
  • Posts: 17
  • Thank you received: 0
Guys, thanks.
Adding the trailing slash onto root_file_path did the trick:
C:/Apache24/htdocs/zone2.derbylearn.net/moodle/xertetoolkits/

I've done the same for import_path (assumption on my part).

I think getting the additional debug entry as per Tom's post would be a good idea. What would also be really helpful would be documentation regarding formatting of some of the fields (i.e. required trailing path separators, use of '/' or '\' for Windows environments and use of drive specifier for Winodows environments.

For the best solution, it would be great to have some checks on the configuration files (including trailing slash for example, or even dummy write/read/delete/read[not found] into the USER-FILES folder would be good to quickly identify and resolve R/W errors on some of the standard config paths.

Thanks for your help, it has been most appreciated.

Kind Regards,
Chris

Please Inloggen or Create an account to join the conversation.

Moderators: ronmjultenJohnSmith
Time to create page: 0.057 seconds
Copyright © 2024 The Xerte Project.
Xerte logo Apereo logo OSI Logo

Search