Posts Tagged ‘Aha-Erlebnis’

Concrete5 and db.xml

Tuesday, March 23rd, 2010

How does the installation of a db.xml file in the package root directory work?

I need to create tables for my Dashboard Application (Import Wizard), which will not be used by blocks – the Import Wizard does not contain any blocks.

In the Concrete5 forum, a function installDB was mentioned. It's defined in the InstallController class like this:

protected function installDB() {

$installDirectory = $this->installData['DIR_BASE_CORE'] . '/config';
$file = $installDirectory . '/db.xml';
if (!file_exists($file)) {
throw new Exception(t('Unable to locate database import file.'));
}

$db = Loader::db();
$db->ensureEncoding();
$err = Package::installDB($file);

}

It ensures the db.xml file exists and after some other setup steps and check finally calls Package::installDB (Package is a model):

public static function installDB($xmlFile) {

if (!file_exists($xmlFile)) {
return false;
}

// currently this is just done from xml

$db = Loader::db();

// this sucks – but adodb generates errors at the beginning because it attempts
// to find a table that doesn't exist!

$handler = $db->IgnoreErrors();
if ($db->getDebug() == false) {
ob_start();
}

$schema = $db->getADOSChema();
$sql = $schema->ParseSchema($xmlFile);

$db->IgnoreErrors($handler);

if (!$sql) {
$result->message = $db->ErrorMsg();
return $result;
}

$r = $schema->ExecuteSchema();

if ($db->getDebug() == false) {
$dbLayerErrorMessage = ob_get_contents();
ob_end_clean();
}

$result = new stdClass;
$result->result = false;

if ($dbLayerErrorMessage != ") {
$result->message = $dbLayerErrorMessage;
return $result;
} if (!$r) {
$result->message = $db->ErrorMsg();
return $result;
}

$result->result = true;

$db->CacheFlush();
return $result;

}

The Code is Copyright by Concrete5 Team.

It looks like I could just drop a db.xml file in my package directory and it will be installed. But how should I name my table?

By convention, there's different prefixes:

  • atX (atAddress, atBoolean, atDateTime) = attribute types
  • btX (btForm, btFlashContent, btSearch) = block types

But there's none for helper tables, to be used just for the Dashboard wizard.

Here's a link to the AdoDB XML Schemas (AXMLS) (the language db.xml is written in). I came up with the following:

<?xml version="1.0"?>
<schema version="0.3">
<table name="IdImportWizardSources">
<field name="ID" type="I">
<key />
<unsigned />
<autoincrement />
</field>
<field name="source" type="X" />
<field name="retrieved" type="T">
<deftimestamp />
</field>
<field name="content" type="B" />

</table>
</schema>

Here I define a new table named IdImportWizardSources (Id for IdeaDay), and several field values using keywords.

Notable is the retrieved field which is automatically set to the current timestamp (deftimestamp). content has a type of BLOB which should be able to store up to 4 GB with MySQL longblob type – unfortunately the amount you can store at once also depends on your MySQL max_packet_size. (Which is usually set to around 16 MB).

The table is imported and set up automatically by Concrete, without a single line o'code.

Was machen wir falsch?

Monday, February 8th, 2010

1212823 money aeroplaneEin Kunde, dem wir immer sehr viel Kulanz und Herzlichkeit entgegengebracht haben, hat Anfang des Jahres abgelehnt, meine Rechnung über 15 * 12 = 180 € für Telefonflat und -Support zu zahlen abgelehnt. Mit der Begründung, er brauche das nicht, da er selten ins Ausland und auf Handys telefoniert. (Neue Preise gültig – gerne auf Anfrage)

Prompt kam es nach Kündigung des Service zum Servicefall, den ich ihm berechnen musste.

Der Kunde sah nicht, dass ihm der Gegenwert dieser Rechnung mehr als gegeben worden war – durch Service, unkomplizierte, kostenlose Auskünfte, und Hinweise auf Einsparpotential durch ehrliche Beratung … er sah das kurzfristige Sparpotential.

Der selbe Kunde zeigte mir einige Zeit drauf stolz seinen neuen iMac. Das hat meine Einstellung einfach grundlegend geändert: vom "er kann es sich nicht leisten" zu "ich verkaufe mich schlecht". Unter Preis. Sozial aber kaufmännisch aberwitzig …

Ich bin Geschäftsmann. Ich biete ehrliche Preise für guten Service. Ich will es halten wie der Geschäftsführer eines Abbeizunternehmens. Dieser wollte nicht mit dem Preis runtergehen, mit der Begründung, dass er dann seine Leute auf die Straße setzen müsste. Recht hat er!

(Bild: steved_np3 // sxc.hu)