[Typo3-dev] Copy page tree with custom PHP code
Peter Beernink (DRecomm)
p.beernink at drecomm.nl
Tue Jan 18 09:02:33 CET 2005
Hi list,
The following mail was first send to the typo3-english list. Since I guess this
message is a bit to technical for that list, I try it here.
For a client I have written a standalone script which checks if there is a new
fe_user in a certain fe_group.
After that it creates a new be_user and copies a part of the page tree, like
freesite.
For this I've used some parts of the freesite extention.
However, the problem is that the content isn't copied while creating the pages,
so only empty pages are created.
Except for storage folders on which the content was copied.
I couln't find any reason why the content shouldn't be copied.
Below are the important parts from the script.
Is there any thing I overlooked?
Code:
#! /usr/bin/php -q
<?php
/* Some requirements copied from dmailerd.phpcron and init.php */
$dir = dirname($HTTP_ENV_VARS["_"]);
define("PATH_typo3", dirname(dirname(dirname($dir)))."/typo3/");
define("PATH_site", dirname(PATH_typo3)."/");
define("PATH_t3lib", PATH_typo3."t3lib/");
define("PATH_tslib", PATH_typo3."../tslib/");
define("PATH_typo3conf", PATH_site."typo3conf/"); // Typo-configuraton
path
define('TYPO3_MODE','BE');
define('TYPO3_OS', stristr(PHP_OS,'win')&&!stristr(PHP_OS,'darwin')?'WIN':'');
require(PATH_t3lib."class.t3lib_div.php");
require(PATH_t3lib."class.t3lib_extmgm.php");
require(PATH_t3lib."class.t3lib_tcemain.php");
require(PATH_t3lib."class.t3lib_userauth.php");
require(PATH_t3lib."class.t3lib_userauthgroup.php");
require(PATH_t3lib."class.t3lib_beuserauth.php");
require(PATH_t3lib."class.t3lib_befunc.php");
require(PATH_t3lib."config_default.php");
if (!defined ("TYPO3_db")) die ("The configuration file was not
included.");
require(PATH_t3lib.'class.t3lib_db.php'); // The database library
$TYPO3_DB = t3lib_div::makeInstance('t3lib_DB');
$result = $GLOBALS['TYPO3_DB']->sql_pconnect(TYPO3_db_host, TYPO3_db_username,
TYPO3_db_password);
$GLOBALS['TYPO3_DB']->sql_select_db(TYPO3_db);
require(PATH_tslib."class.tslib_fe.php");
// ****************************************************
// Include tables customization (tables + ext_tables)
// ****************************************************
include (TYPO3_tables_script ? PATH_typo3conf.TYPO3_tables_script :
PATH_t3lib.'stddb/tables.php');
// Extension additions
if ($TYPO3_LOADED_EXT['_CACHEFILE']) {
include (PATH_typo3conf.$TYPO3_LOADED_EXT['_CACHEFILE'].'_ext_tables.php');
} else {
include (PATH_t3lib.'stddb/load_ext_tables.php');
}
// extScript
if (TYPO3_extTableDef_script) {
include (PATH_typo3conf.TYPO3_extTableDef_script);
}
GLOBAL $TCA;
tslib_fe::includeTCA(0);
// Now select all users for which the site should be created
/*.. [snip] ../*
// We have created a new user, now copy the page tree
$tce = t3lib_div::makeInstance("t3lib_TCEmain");
$tce->stripslashes_values=0;
$tce->copyTree=2;
$tce->neverHideAtCopy=1;
$user_object = t3lib_div::makeInstance
("t3lib_beUserAuth");
$user_object->OS = TYPO3_OS;
$user_object->setBeUserByUid($be_user_uid);
$user_object->fetchGroupData();
$user_object->user["admin"] = 1;
$cmd=array();
$cmd["pages"][$PAGE_TEMPLATE]["copy"]=$PID_SITES;
$tce->start(array(),$cmd,$user_object);
$tce->process_cmdmap();
unset($user_object);
// Get the root of the newly created key
$root_page_pid = $tce->copyMappingArray["pages"]
[$PAGE_TEMPLATE];
if ($root_page_pid) {
$this->createTemplateRecord
($root_page_pid,$this->getRootPageTitle());
}
// Now only set the page title of the root page.
/***** END OF CODE ****/
The above code was found in the freesite extension. I couldn't find any reason
why this shouldn't work.
Does anyone have a clue what the problem might be?
Greetings,
Peter
More information about the TYPO3-dev
mailing list