This Help forum is for issues relates to the latest release (1.7.8). For issues related to beta or github version please use their own Help forum.
Before asking for help please read "How to request help" by clicking on that tab above here."

TOPIC: Autoexport of Trees with cron

Autoexport of Trees with cron 2 years 1 month ago #1

  • HonkXL
  • HonkXL's Avatar
  • Offline
  • Junior
  • Posts: 144
Hi,

in www.webtrees.net/index.php/en/forum/help...gedcom-with-cron-job
I asked for an skript to export my trees as GEDCOM using cron. The script below worked fine as I only had one tree. Now I created a second tree in Webtrees, but this script is only exporting the first tree.

User #1 is a user that really has full access to both trees.
I know that this is not really part of webtrees itself, but maybe someone can help me, as I am not very good in changing PHP scripts.

Any idea how to fix this to get all trees exported?
<?php
define('WT_SCRIPT_NAME', 'test.php');
// Pretend to be USER #1, with a real browser
$_SESSION['wt_user'] = 1;
$_SERVER['HTTP_USER_AGENT'] = 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:43.0) Gecko/20100101 Firefox/43.0';
require 'includes/session.php';
foreach (\Fisharebest\webtrees\Tree::getAll() as $tree) {
        $stream = fopen($tree->getName() . '.GED', 'w');
        $tree->exportGedcom($stream);
        fclose($stream);
}
My homepage: www.weiland24.de
My webtrees: webtrees.weiland24.de
The administrator has disabled public write access.

Autoexport of Trees with cron 2 years 1 month ago #2

  • thomas52
  • thomas52's Avatar
  • Online
  • Frequent
  • Western North Carolina
  • Posts: 770
Might this be set up as a module?
"Failure is an amazing teacher." (L'échec est un professeur extraordinaire.)
The administrator has disabled public write access.

Autoexport of Trees with cron 2 years 1 month ago #3

  • fisharebest
  • fisharebest's Avatar
  • Offline
  • Administrator
  • Posts: 10615
The code to export all the trees is simple. It is part of the auto-upgrade system.

See github.com/fisharebest/webtrees/blob/mas...ite_upgrade.php#L219
Greg Roach - This email address is being protected from spambots. You need JavaScript enabled to view it. - fisharebest.webtrees.net
The administrator has disabled public write access.

Autoexport of Trees with cron 2 years 1 month ago #4

  • HonkXL
  • HonkXL's Avatar
  • Offline
  • Junior
  • Posts: 144
Thank you! I tried to code a autoexport script. It works now for all public trees, but not for trees that are only visible to logged in users.
But the two lines
$_SESSION = 1;
$_SERVER = 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:43.0) Gecko/20100101 Firefox/43.0';
should set this, right?

Do you have a idea what here can be wrong?
This is the code I use now:
<?php
namespace Fisharebest\Webtrees;

use Exception;
use Fisharebest\Webtrees\Controller\PageController;
use Fisharebest\Webtrees\Functions\Functions;
use Fisharebest\Webtrees\Functions\FunctionsDate;
use PclZip;

define('WT_SCRIPT_NAME', 'autoexport.php');
// Pretend to be USER #1, with a real browser
$_SESSION['wt_user'] = 1;
$_SERVER['HTTP_USER_AGENT'] = 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:43.0) Gecko/20100101 Firefox/43.0';

require './includes/session.php';

foreach (Tree::getAll() as $tree) {
    reset_timeout();
    $filename = WT_DATA_DIR . $tree->getName() . '.ged';
    try {
	// To avoid partial trees on timeout/diskspace/etc, write to a temporary file first
        $stream = fopen($filename . '.tmp', 'w');
        $tree->exportGedcom($stream);
        fclose($stream);
        rename($filename . '.tmp', $filename);
        echo 'The family tree has been exported to %s.', Html::filename($filename);
    } catch (\ErrorException $ex) {
	echo 'The file %s could not be created.', Html::filename($filename);
    }
}


function reset_timeout() {
    if (!ini_get('safe_mode') && strpos(ini_get('disable_functions'), 'set_time_limit') === false) {
	try {
	    set_time_limit(ini_get('max_execution_time'));
	} catch (Exception $ex) {
	    // "set_time_limt(): Cannot set max execution time limit due to system policy"
	}
    }
}


?>
My homepage: www.weiland24.de
My webtrees: webtrees.weiland24.de
The administrator has disabled public write access.

Autoexport of Trees with cron 2 years 1 month ago #5

  • fisharebest
  • fisharebest's Avatar
  • Offline
  • Administrator
  • Posts: 10615
Are you running this using the cron command (i.e. as a command line script from the local host), or are using the word "cron" to mean a "generic scheduled task.
Greg Roach - This email address is being protected from spambots. You need JavaScript enabled to view it. - fisharebest.webtrees.net
The administrator has disabled public write access.

Autoexport of Trees with cron 2 years 1 month ago #6

  • HonkXL
  • HonkXL's Avatar
  • Offline
  • Junior
  • Posts: 144
Hi, I use cron, but I start the php using wget - this mean wget https://....

This is because I have more than one php version on the server and sometimes I change them and this can be a problem when I call php directly from cron scripts.
But: should this make a difference in this case?
My homepage: www.weiland24.de
My webtrees: webtrees.weiland24.de
The administrator has disabled public write access.

Autoexport of Trees with cron 2 years 1 month ago #7

  • fisharebest
  • fisharebest's Avatar
  • Offline
  • Administrator
  • Posts: 10615
> I start the php using wget - this mean wget https://....

Not really necessary. Just call the script directly. Here's a line from the crontab file on my own server, which runs a PHP script to update the statistics page:
50 5 * * * php bin/statistics.php

i.e. at 05:50 on every day of the week, use PHP to run the script bin/statistics.php
Greg Roach - This email address is being protected from spambots. You need JavaScript enabled to view it. - fisharebest.webtrees.net
The administrator has disabled public write access.

Autoexport of Trees with cron 2 years 2 weeks ago #8

  • HonkXL
  • HonkXL's Avatar
  • Offline
  • Junior
  • Posts: 144
I tried to run this from the ssh shell - nothing changed - it's the same result as running by web-cron: only the first tree has been exported.
My homepage: www.weiland24.de
My webtrees: webtrees.weiland24.de
The administrator has disabled public write access.
Do you need a web hosting solution for your webtrees site?
If you prefer a host that specialises in webtrees, the following page lists some suppliers able to provide one for you: 

Autoexport of Trees with cron 2 years 2 weeks ago #9

  • fisharebest
  • fisharebest's Avatar
  • Offline
  • Administrator
  • Posts: 10615
> only the first tree has been exported.

This line will only process the trees that the current user is allowed to see.
foreach (\Fisharebest\webtrees\Tree::getAll() as $tree)

Presumably webtrees is not recognising you as an administrator.
Perhaps you also need this to complete the session initialisation
$_SESSION['initiated'] = true;

Alternatively, look at one of the scripts that does not call includes/session.php (maybe site-unavailable.php) and base your code on that instead.
Greg Roach - This email address is being protected from spambots. You need JavaScript enabled to view it. - fisharebest.webtrees.net
The administrator has disabled public write access.

Autoexport of Trees with cron 2 years 2 weeks ago #10

  • HonkXL
  • HonkXL's Avatar
  • Offline
  • Junior
  • Posts: 144
Thank you. It is not working with this changes. But I found out, that it exports all my trees that are visible to visitors.
So I changed all trees to visible and hide all data -> this works...

I think this is the easiest way to handle this.

Great: now I can auto-export my trees and upload them to a second server using a cron job :-)
My homepage: www.weiland24.de
My webtrees: webtrees.weiland24.de
The administrator has disabled public write access.
Powered by Kunena Forum