/** * installs a block type * @param string $btHandle * @param BlockType $bt * @param string $dir * @param int $btID * @param string $dirDbXml */ protected function doInstallBlockType($btHandle, $bt, $dir, $btID = 0, $dirDbXml) { $db = Loader::db(); $env = Environment::get(); $env->clearOverrideCache(); if (file_exists($dir . '/' . $btHandle . '/' . FILENAME_BLOCK_CONTROLLER)) { $class = $bt->getBlockTypeClass(); $path = $dirDbXml . '/' . $btHandle; if (!class_exists($class)) { require_once($dir . '/' . $btHandle . '/' . FILENAME_BLOCK_CONTROLLER); } if (!class_exists($class)) { throw new Exception(t("%s not found. Please check that the block controller file contains the correct class name.", $class)); } $bta = new $class; //Attempt to run the subclass methods (install schema from db.xml, etc.) $r = $bta->install($path); //Validate if ($r === false) { return t('Error: Block Type cannot be installed because no db.xml file can be found. Either create a db.xml file for this block type, or remove the $btTable variable from its controller.'); } else if (!$r->result && $r->message) { return $r->message; } else if (!$r->result && !$r->message) { return t('Error: Block Type cannot be installed due to an unknown database error. Please check that the db.xml file for this block type is formatted correctly.'); } else if ($message = BlockType::validateInstalledDatabaseTable($bta->getBlockTypeDatabaseTable())) { $db->Execute('DROP TABLE IF EXISTS ' . $bta->getBlockTypeDatabaseTable()); return $message; } $currentLocale = Localization::activeLocale(); if ($currentLocale != 'en_US') { // Prevent the database records being stored in wrong language Localization::changeLocale('en_US'); } //Install the block $btd = new BlockTypeDB(); $btd->btHandle = $btHandle; $btd->btName = $bta->getBlockTypeName(); $btd->btDescription = $bta->getBlockTypeDescription(); $btd->btActiveWhenAdded = $bta->isActiveWhenAdded(); $btd->btCopyWhenPropagate = $bta->isCopiedWhenPropagated(); $btd->btIncludeAll = $bta->includeAll(); $btd->btIsInternal = $bta->isBlockTypeInternal(); $btd->btInterfaceHeight = $bta->getInterfaceHeight(); $btd->btInterfaceWidth = $bta->getInterfaceWidth(); $btd->pkgID = $bt->getPackageID(); if ($currentLocale != 'en_US') { Localization::changeLocale($currentLocale); } if ($btID > 0) { $btd->btID = $btID; $btDisplayOrder = $db->GetOne('select btDisplayOrder from BlockTypes where btID = ?', array($btID)); if (!$btDisplayOrder) { $btDisplayOrder = 0; } $btd->btDisplayOrder = $btDisplayOrder; $r = $btd->Replace(); } else { if ($bta->isBlockTypeInternal()) { $btd->btDisplayOrder = 0; } else { $btMax = $db->GetOne('select max(btDisplayOrder) from BlockTypes'); if ($btMax < 1 && $btMax !== '0') { $btd->btDisplayOrder = 0; } else { $btd->btDisplayOrder = $btMax + 1; } } $r = $btd->save(); } // now we remove the block type from cache $ca = new Cache(); $ca->delete('blockTypeByID', $btID); $ca->delete('blockTypeByHandle', $btHandle); $ca->delete('blockTypeList', false); if (!$r) { return $db->ErrorMsg(); } } else { return t("No block found with the handle %s.", $btHandle); } }
/** * installs a block type * @param string $btHandle * @param BlockType $bt * @param string $dir * @param int $btID */ protected function doInstallBlockType($btHandle, $bt, $dir, $btID = 0) { $db = Loader::db(); if (file_exists($dir . '/' . $btHandle . '/' . FILENAME_BLOCK_CONTROLLER)) { $class = $bt->getBlockTypeClassFromHandle(); $path = $dir . '/' . $btHandle; if (!class_exists($class)) { require_once $dir . '/' . $btHandle . '/' . FILENAME_BLOCK_CONTROLLER; } if (!class_exists($class)) { throw new Exception(t("%s not found. Please check that the block controller file contains the correct class name.", $class)); } $bta = new $class(); // first run the subclass methods. If they work then we install the block $r = $bta->install($path); if (!$r->result) { return $r->message; } $btd = new BlockTypeDB(); $btd->btHandle = $btHandle; $btd->btName = $bta->getBlockTypeName(); $btd->btDescription = $bta->getBlockTypeDescription(); $btd->btActiveWhenAdded = $bta->isActiveWhenAdded(); $btd->btCopyWhenPropagate = $bta->isCopiedWhenPropagated(); $btd->btIncludeAll = $bta->includeAll(); $btd->btIsInternal = $bta->isBlockTypeInternal(); $btd->btInterfaceHeight = $bta->getInterfaceHeight(); $btd->btInterfaceWidth = $bta->getInterfaceWidth(); $btd->pkgID = $bt->getPackageID(); if ($btID > 0) { $btd->btID = $btID; $r = $btd->Replace(); } else { $r = $btd->save(); } // now we remove the block type from cache $ca = new Cache(); $ca->delete('blockTypeByID', $btID); $ca->delete('blockTypeByHandle', $btHandle); $ca->delete('blockTypeList', false); if (!$r) { return $db->ErrorMsg(); } } else { return t("No block found with the handle %s.", $btHandle); } }