Web based family history software

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."

Question Autoexport of Trees with cron

  • HonkXL
  • Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
7 years 3 months ago #1 by HonkXL
Autoexport of Trees with cron was created by HonkXL
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?
Code:
<?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); }

Please Log in or Create an account to join the conversation.

  • thomas52
  • Offline
  • Premium Member
  • Premium Member
  • Western North Carolina
More
7 years 3 months ago #2 by thomas52
Replied by thomas52 on topic Autoexport of Trees with cron
Might this be set up as a module?

"Failure is an amazing teacher." (L'échec est un professeur extraordinaire.)

Please Log in or Create an account to join the conversation.

More
7 years 3 months ago #3 by fisharebest
Replied by fisharebest on topic Autoexport of Trees with cron
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 - greg@subaqua.co.uk - @fisharebest@phpc.social - fisharebest.webtrees.net

Please Log in or Create an account to join the conversation.

  • HonkXL
  • Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
7 years 3 months ago #4 by HonkXL
Replied by HonkXL on topic Autoexport of Trees with cron
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:
Code:
<?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" } } } ?>

Please Log in or Create an account to join the conversation.

More
7 years 3 months ago #5 by fisharebest
Replied by fisharebest on topic Autoexport of Trees with cron
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 - greg@subaqua.co.uk - @fisharebest@phpc.social - fisharebest.webtrees.net

Please Log in or Create an account to join the conversation.

  • HonkXL
  • Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
7 years 3 months ago #6 by HonkXL
Replied by HonkXL on topic Autoexport of Trees with cron
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?

Please Log in or Create an account to join the conversation.

More
7 years 3 months ago #7 by fisharebest
Replied by fisharebest on topic Autoexport of Trees with cron
> 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:
Code:
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 - greg@subaqua.co.uk - @fisharebest@phpc.social - fisharebest.webtrees.net

Please Log in or Create an account to join the conversation.

  • HonkXL
  • Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
7 years 2 months ago #8 by HonkXL
Replied by HonkXL on topic Autoexport of Trees with cron
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.

Please Log in or Create an account to join the conversation.

More
7 years 2 months ago #9 by fisharebest
Replied by fisharebest on topic Autoexport of Trees with cron
> only the first tree has been exported.

This line will only process the trees that the current user is allowed to see.
Code:
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
Code:
$_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 - greg@subaqua.co.uk - @fisharebest@phpc.social - fisharebest.webtrees.net

Please Log in or Create an account to join the conversation.

  • HonkXL
  • Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
7 years 2 months ago #10 by HonkXL
Replied by HonkXL on topic Autoexport of Trees with cron
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 :-)

Please Log in or Create an account to join the conversation.

Powered by Kunena Forum
}