eZ Community » Forums » Extensions » Website Interface » How can I keep the same classes on...
expandshrink

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

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

Thursday 18 December 2008 1:20:18 pm - 5 replies

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.

Thursday 18 December 2008 2:02:27 pm

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.

Thursday 18 December 2008 2:17:22 pm

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.

 

Modified on Thursday 18 December 2008 2:24:29 pm by florian bellenger

Wednesday 20 May 2009 2:39:23 pm

create an extension cronjob export->import

Wednesday 20 May 2009 2:40:26 pm

or create a workflow after published to syncro

Wednesday 20 May 2009 3:14:23 pm

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 = 'gg@ez.no';
$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 );
}

?>

Modified on Wednesday 20 May 2009 3:14:56 pm by Gaetano Giunta

expandshrink

You must be logged in to post messages in this topic!

36 542 Users on board!

Forums menu

Proudly Developed with from