How can I keep the same classes on two ezpublish websites?

Author Message

florian bellenger

Thursday 18 December 2008 4:20:18 am

Good afternoon,

I have two ezpublish websites.They both have their own files and their own database.

But they have the same classes.

When I create/publish a new class within the website interface of the first website, I would like it to be automatically created within the website interface of the second website.(I am doing it by hand but it takes time and I could make a mistake.)

When I modify an existing class within the website interface of the first website, I would like it to be automatically modified within the website interface of the second website.

Is there any existing solution for that kind of problem?

Florian.

Patrick Kaiser

Thursday 18 December 2008 5:02:27 am

why do you use two databases for your websites? if you have the same classes and you want to share content between your sites you should consider using only one database.


Best regards,

Patrick

florian bellenger

Thursday 18 December 2008 5:17:22 am

In fact, the content are not the same between the two databases.

I also use the first website (and its database) to test new extensions or new templates.

So, if I have a problem with the database of the first website, I don't want the second one to be concerned.

Florian.

 

Bin LIU

Wednesday 20 May 2009 5:39:23 am

create an extension cronjob export->import

=== Lagardère Active ===

Fetch random
http://projects.ez.no/la_fetch_random
LA Static Cache
http://projects.ez.no/lastaticcache
LA Bookmarks (jquery)
http://projects.ez.no/labookmark
LA Calendar (jquery)
http://projects.ez.no/lacalendar

My site ez
http://lingping.info

Bin LIU

Wednesday 20 May 2009 5:40:26 am

or create a workflow after published to syncro

=== Lagardère Active ===

Fetch random
http://projects.ez.no/la_fetch_random
LA Static Cache
http://projects.ez.no/lastaticcache
LA Bookmarks (jquery)
http://projects.ez.no/labookmark
LA Calendar (jquery)
http://projects.ez.no/lacalendar

My site ez
http://lingping.info

Gaetano Giunta

Wednesday 20 May 2009 6:14:23 am

This cronjob creates a package for every class, automatically bumping up the version only when classes are updated:

<?php
/**
 * Cronjob that will export all classes definition as a package file.
 * Will only update the package if classes have been modified since last version
 *
 * @author G. Giunta
 * @version $Id$
 * @copyright 2009
 *
 * @todo add an ini file to get the parameters from
 */

$packagename = 'classes_mysite';
$packagesummary = 'Export of all the classes of the website';
$packagecreatorname = 'eZ Publish';
$packagecreatoremail = '[email protected]';
$packageexportdir = '';


// create or open existing package
$package = eZPackage::fetch( $packagename );
if ( !$package )
{
    if ( !$isQuiet )
        $cli->output( 'Creating package ' . $packagename );
    $package = eZPackage::create( $packagename,
                                  array( 'summary' => $packagesummary ),
                                  false, false );
    $package->setAttribute( 'install_type', 'install' );
    $package->setAttribute( 'type', 'contentclass' );
    $package->appendChange( $packagecreatorname, $packagecreatoremail, 'Package created' );

    $lastsavedate = 0;
    $packageversion = '1.0';
}
else
{
    $lastsavedate = $package->attribute( 'release-timestamp' );
    $packageversion = $package->attribute( 'version-number' );
}

// find date of last modification of classes
$classes = eZContentClass::fetchList( eZContentClass::VERSION_STATUS_DEFINED, true );
$lastmodification = 0;
foreach( $classes as $class )
{
    if ( $class->attribute( 'modified' ) > $lastmodification )
    {
        $lastmodification = $class->attribute( 'modified' );
    }
    if ( $class->attribute( 'created' ) > $lastmodification )
    {
        $lastmodification = $class->attribute( 'created' );
    }
}

// if no class has changed since last release, quit
if ( $lastmodification <= $lastsavedate && $lastsavedate > 0 )
{
    if ( !$isQuiet )
        $cli->output( 'No class has been modified since last package save. Aborting' );
}
else
{
    if ( $lastsavedate > 0 )
    {
        if ( !$isQuiet )
            $cli->output( 'Updating package ' . $packagename );
    }

    // we always increment the minor version
    $major = substr( $packageversion , 0, strpos( $packageversion, '.' ) );
    $packageversion = substr( $packageversion , strpos( $packageversion, '.' ) + 1 );
    $packageversion = $major . '.' . ( $packageversion + 1 );
    // the release date is set to last date of modification of classes
    $package->setRelease( $packageversion, '1', $lastmodification );

    $handler = $package->packageHandler( 'ezcontentclass' );
    $classlist = array();
    foreach( $classes as $class )
    {
        if ( $class->attribute( 'modified' ) > $lastsavedate ||  $class->attribute( 'created' ) > $lastsavedate )
        {
            $classlist[] = $class->attribute( 'identifier' );
            $parameters = $handler->handleAddParameters( 'ezcontentclass', $package, $cli, array( $class->attribute( 'identifier' ) ) );
            $handler->add( 'ezcontentclass', $package, $cli, $parameters );
        }
    }
    $classlist = implode( ', ', $classlist );
    $package->appendChange( $packagecreatorname, $packagecreatoremail, 'Added classes ' . $classlist );
    $package->store();
    //$cli->output( 'Added classes ' . $classlist );

    $outputfilename = $packageexportdir . eZSys::fileSeparator() . $package->exportName();
    $package->exportToArchive( $outputfilename );
    if ( !$isQuiet )
        $cli->output( 'Saved file ' . $outputfilename );
}

?>

Principal Consultant International Business
Member of the Community Project Board

Powered by eZ Publish™ CMS Open Source Web Content Management. Copyright © 1999-2014 eZ Systems AS (except where otherwise noted). All rights reserved.