本文整理汇总了PHP中ClassInfo::hasTable方法的典型用法代码示例。如果您正苦于以下问题:PHP ClassInfo::hasTable方法的具体用法?PHP ClassInfo::hasTable怎么用?PHP ClassInfo::hasTable使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ClassInfo
的用法示例。
在下文中一共展示了ClassInfo::hasTable方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: handleRequest
/**
* @uses ModelAsController::getNestedController()
* @param SS_HTTPRequest $request
* @param DataModel $model
* @return SS_HTTPResponse
*/
public function handleRequest(SS_HTTPRequest $request, DataModel $model)
{
$this->setRequest($request);
$this->setDataModel($model);
$this->pushCurrent();
// Create a response just in case init() decides to redirect
$this->response = new SS_HTTPResponse();
$this->init();
// If we had a redirection or something, halt processing.
if ($this->response->isFinished()) {
$this->popCurrent();
return $this->response;
}
// If the database has not yet been created, redirect to the build page.
if (!DB::is_active() || !ClassInfo::hasTable('SiteTree')) {
$this->response->redirect(Director::absoluteBaseURL() . 'dev/build?returnURL=' . (isset($_GET['url']) ? urlencode($_GET['url']) : null));
$this->popCurrent();
return $this->response;
}
try {
$result = $this->getNestedController();
if ($result instanceof RequestHandler) {
$result = $result->handleRequest($this->getRequest(), $model);
} else {
if (!$result instanceof SS_HTTPResponse) {
user_error("ModelAsController::getNestedController() returned bad object type '" . get_class($result) . "'", E_USER_WARNING);
}
}
} catch (SS_HTTPResponse_Exception $responseException) {
$result = $responseException->getResponse();
}
$this->popCurrent();
return $result;
}
示例2: truncate_table
private static function truncate_table($table)
{
if (ClassInfo::hasTable($table)) {
if (method_exists(DB::getConn(), 'clearTable')) {
DB::getConn()->clearTable($table);
} else {
DB::query("TRUNCATE \"{$table}\"");
}
}
}
示例3: run
public function run($request)
{
HTTP::set_cache_age(0);
increase_time_limit_to();
// This can be a time consuming task
$conn = DB::getConn();
$classes = ClassInfo::subclassesFor('DataObject');
$dbTables = $conn->tableList();
$go = $request->getVar('go');
if (!$go) {
echo 'Set ?go=1 to really delete the tables';
echo '<hr/>';
}
//make all lowercase
$dbTablesLc = array_map('strtolower', $dbTables);
$dbTablesMap = array();
foreach ($dbTables as $k => $v) {
$dbTablesMap[strtolower($v)] = $v;
}
foreach ($classes as $class) {
if (ClassInfo::hasTable($class)) {
$lcClass = strtolower($class);
self::removeFromArray($lcClass, $dbTablesLc);
//page modules
self::removeFromArray($lcClass . '_live', $dbTablesLc);
self::removeFromArray($lcClass . '_versions', $dbTablesLc);
//relations
$hasMany = Config::inst()->get($class, 'has_many');
$manyMany = Config::inst()->get($class, 'many_many');
if (!empty($hasMany)) {
foreach ($hasMany as $rel => $obj) {
self::removeFromArray($lcClass . '_' . strtolower($rel), $dbTablesLc);
}
}
if (!empty($manyMany)) {
foreach ($manyMany as $rel => $obj) {
self::removeFromArray($lcClass . '_' . strtolower($rel), $dbTablesLc);
}
}
}
}
//at this point, we should only have orphans table in dbTables var
foreach ($dbTablesLc as $i => $lcTable) {
$table = $dbTablesMap[$lcTable];
if ($go) {
DB::query('DROP TABLE `' . $table . '`');
DB::alteration_message("Dropped {$table}", 'obsolete');
} else {
DB::alteration_message("Would drop {$table}", 'obsolete');
}
}
}
示例4: handleRequest
public function handleRequest($request)
{
self::$is_at_root = true;
$this->pushCurrent();
$this->init();
// If the basic database hasn't been created, then build it.
if (!DB::isActive() || !ClassInfo::hasTable('SiteTree')) {
$this->response = new HTTPResponse();
$this->redirect("dev/build?returnURL=");
return $this->response;
}
$controller = new ModelAsController();
$request = new HTTPRequest("GET", self::get_homepage_urlsegment() . '/', $request->getVars(), $request->postVars());
$request->match('$URLSegment//$Action', true);
$result = $controller->handleRequest($request);
$this->popCurrent();
return $result;
}
示例5: handleRequest
/**
* Check catalogue URL's before we get to the CMS (if it exists)
*
* @param SS_HTTPRequest $request
* @param DataModel|null $model
* @return SS_HTTPResponse
*/
public function handleRequest(SS_HTTPRequest $request, DataModel $model)
{
$this->request = $request;
$this->setDataModel($model);
$catalogue_enabled = Catalogue::config()->enable_frontend;
$this->pushCurrent();
// Create a response just in case init() decides to redirect
$this->response = new SS_HTTPResponse();
$this->init();
// If we had a redirection or something, halt processing.
if ($this->response->isFinished()) {
$this->popCurrent();
return $this->response;
}
// If DB is not present, build
if (!DB::isActive() || !ClassInfo::hasTable('CatalogueProduct') || !ClassInfo::hasTable('CatalogueCategory')) {
return $this->response->redirect(Director::absoluteBaseURL() . 'dev/build?returnURL=' . (isset($_GET['url']) ? urlencode($_GET['url']) : null));
}
$urlsegment = $request->param('URLSegment');
$this->extend('onBeforeInit');
$this->init();
$this->extend('onAfterInit');
// Find link, regardless of current locale settings
if (class_exists('Translatable')) {
Translatable::disable_locale_filter();
}
$filter = array('URLSegment' => $urlsegment, 'Disabled' => 0);
if ($catalogue_enabled && ($object = CatalogueProduct::get()->filter($filter)->first())) {
$controller = $this->controller_for($object);
} elseif ($catalogue_enabled && ($object = CatalogueCategory::get()->filter($filter)->first())) {
$controller = $this->controller_for($object);
} elseif (class_exists('ModelAsController')) {
// If CMS installed
$controller = ModelAsController::create();
} else {
$controller = Controller::create();
}
if (class_exists('Translatable')) {
Translatable::enable_locale_filter();
}
$result = $controller->handleRequest($request, $model);
$this->popCurrent();
return $result;
}
示例6: handleRequest
public function handleRequest($request)
{
$this->pushCurrent();
$this->urlParams = $request->allParams();
$this->init();
// If the basic database hasn't been created, then build it.
if (!DB::isActive() || !ClassInfo::hasTable('SiteTree')) {
$this->response = new HTTPResponse();
$this->redirect("dev/build?returnURL=" . (isset($_GET['url']) ? urlencode($_GET['url']) : ''));
$this->popCurrent();
return $this->response;
}
$result = $this->getNestedController();
if (is_object($result) && $result instanceof RequestHandler) {
$result = $result->handleRequest($request);
}
$this->popCurrent();
return $result;
}
示例7: run
public function run($request)
{
$classes = ClassInfo::subclassesFor('DataObject');
$dbTables = DB::query(DB::getConn()->allTablesSQL())->column();
$go = $request->getVar('go');
if (!$go) {
DB::alteration_message('Set ?go=1 to really delete the tables');
}
//make all lowercase
$dbTablesLc = array_map('strtolower', $dbTables);
foreach ($classes as $class) {
if (ClassInfo::hasTable($class)) {
$lcClass = strtolower($class);
self::removeFromArray($lcClass, $dbTablesLc);
//page modules
self::removeFromArray($lcClass . '_live', $dbTablesLc);
self::removeFromArray($lcClass . '_versions', $dbTablesLc);
//relations
$hasMany = Config::inst()->get($class, 'has_many');
$manyMany = Config::inst()->get($class, 'many_many');
if (!empty($hasMany)) {
foreach ($hasMany as $rel => $obj) {
self::removeFromArray($lcClass . '_' . strtolower($rel), $dbTablesLc);
}
}
if (!empty($manyMany)) {
foreach ($manyMany as $rel => $obj) {
self::removeFromArray($lcClass . '_' . strtolower($rel), $dbTablesLc);
}
}
}
}
//at this point, we should only have orphans table in dbTables var
foreach ($dbTablesLc as $i => $table) {
if ($go) {
DB::query('DROP TABLE `' . $table . '`');
DB::alteration_message("Dropped {$table}", 'obsolete');
} else {
DB::alteration_message("Would drop {$table}", 'obsolete');
}
}
}
示例8: run
public function run($request)
{
HTTP::set_cache_age(0);
increase_time_limit_to();
// This can be a time consuming task
$classes = ClassInfo::dataClassesFor('DataObject');
$conn = DB::getConn();
$go = $request->getVar('go');
if (!$go) {
echo 'Set ?go=1 to really delete the fields';
echo '<hr/>';
}
foreach ($classes as $class) {
$hasTable = ClassInfo::hasTable($class);
if (!$hasTable) {
continue;
}
$toDrop = array();
$fields = $class::database_fields($class);
$list = $conn->fieldList($class);
foreach ($list as $fieldName => $type) {
if ($fieldName == 'ID') {
continue;
}
if (!isset($fields[$fieldName])) {
$toDrop[] = $fieldName;
}
}
if (empty($toDrop)) {
continue;
}
if ($go) {
$this->dropColumns($class, $toDrop);
DB::alteration_message("Dropped " . implode(',', $toDrop) . " for {$class}", "obsolete");
} else {
DB::alteration_message("Would drop " . implode(',', $toDrop) . " for {$class}", "obsolete");
}
}
}
示例9: _getAnnouncement
public function _getAnnouncement($render = true)
{
if (ClassInfo::hasTable('MediaHolder')) {
$media = MediaHolder::get()->filter(array('MediaType.Title' => 'News'));
$possible = $media->first();
// what about an announcement title'd page
$page = $media->filter(array('Title' => 'Announcements'))->first();
if (!$page) {
$page = $possible;
}
if ($page) {
$announcement = MediaPage::get()->filter('ParentID', $page->ID)->sort('Date DESC')->first();
if ($announcement) {
if (!$render) {
return $announcement;
} else {
return ModelAsController::controller_for($announcement)->index();
}
}
}
}
}
示例10: run
function run($request)
{
//TODO: include decendant clases..incase some subclassing has been done somewhere
if ($allorders = DataObject::get('Order')) {
foreach ($allorders as $order) {
$order->delete();
$order->destroy();
}
}
if ($allproducts = DataObject::get('Product')) {
foreach ($allproducts as $product) {
$product->deleteFromStage('Live');
$product->deleteFromStage('Stage');
$product->destroy();
//TODO: remove versions
}
}
//TODO: use TRUNCATE instead?
$basetables = array('Product', 'Product_Live', 'Product_versions', 'Product_ProductGroups', 'Product_OrderItem', 'Product_VariationAttributes', 'ProductVariation', 'ProductVariation_AttributeValues', 'ProductVariation_OrderItem', 'ProductVariation_versions', 'ProductAttributeType', 'ProductAttributeValue');
foreach ($basetables as $table) {
if (!ClassInfo::hasTable($table)) {
continue;
}
foreach (ClassInfo::subclassesFor($table) as $key => $class) {
if (ClassInfo::hasTable($class)) {
DB::query("DELETE FROM \"{$class}\" WHERE 1;");
echo "<p>Deleting all {$class}</p>";
}
}
}
//partial empty queries
echo "<p>Deleting all SiteTree</p>";
DB::query("DELETE FROM \"SiteTree\" WHERE ClassName = 'Product';");
//SiteTree
DB::query("DELETE FROM \"SiteTree_Live\" WHERE ClassName = 'Product';");
//SiteTree
DB::query("DELETE FROM \"SiteTree_versions\" WHERE ClassName = 'Product';");
//SiteTree
}
示例11: handleRequest
public function handleRequest(SS_HTTPRequest $request, DataModel $model = null)
{
self::$is_at_root = true;
$this->setDataModel($model);
$this->pushCurrent();
$this->init();
$this->setRequest($request);
// Check for existing routing parameters, redirecting to another locale automatically if necessary
$locale = Fluent::get_request_locale();
if (empty($locale)) {
// Determine if this user should be redirected
$locale = $this->getRedirectLocale();
$this->extend('updateRedirectLocale', $locale);
// Check if the user should be redirected
$domainDefault = Fluent::default_locale(true);
if (Fluent::is_locale($locale) && $locale !== $domainDefault) {
// Check new traffic with detected locale
return $this->redirect(Fluent::locale_baseurl($locale));
}
// Reset parameters to act in the default locale
$locale = $domainDefault;
Fluent::set_persist_locale($locale);
$params = $request->routeParams();
$params[Fluent::config()->query_param] = $locale;
$request->setRouteParams($params);
}
if (!DB::isActive() || !ClassInfo::hasTable('SiteTree')) {
$this->response = new SS_HTTPResponse();
$this->response->redirect(Director::absoluteBaseURL() . 'dev/build?returnURL=' . (isset($_GET['url']) ? urlencode($_GET['url']) : null));
return $this->response;
}
$localeURL = Fluent::alias($locale);
$request->setUrl(self::fluent_homepage_link($localeURL));
$request->match($localeURL . '/$URLSegment//$Action', true);
$controller = new ModelAsController();
$result = $controller->handleRequest($request, $model);
$this->popCurrent();
return $result;
}
示例12: run
function run($request)
{
if ($allorders = DataObject::get('Order')) {
foreach ($allorders as $order) {
//TODO: delete member(s)?
$order->delete();
$order->destroy();
}
}
$basetables = array('Order', 'OrderAttribute', 'OrderStatusLog', 'Payment');
foreach ($basetables as $table) {
if (!ClassInfo::hasTable($table)) {
continue;
}
foreach (ClassInfo::subclassesFor($table) as $key => $class) {
//TODO: empty all pivot(many_many) tables on this side of relationship
if (ClassInfo::hasTable($class)) {
DB::query("DELETE FROM \"{$class}\" WHERE 1;");
echo "<p>Deleting all {$class}</p>";
}
}
}
}
示例13: run
public function run($request)
{
increase_time_limit_to();
$readingMode = Versioned::get_reading_mode();
Versioned::reading_stage('Stage');
// Make sure that we have something to migrate.
if (!ClassInfo::hasTable('SolrSearchPage')) {
echo "Nothing to Migrate!";
die;
}
// Retrieve the search tree relationships to migrate.
$relationships = array();
if (DB::getConn()->hasTable('SolrSearchPage_SearchTrees')) {
foreach (DB::query('SELECT * FROM SolrSearchPage_SearchTrees') as $relationship) {
$relationships[$relationship['SolrSearchPageID']] = $relationship['PageID'];
}
}
// Store the current live page migration state to avoid duplicates.
$created = array();
// Migrate any live pages to begin with.
$query = DB::query('SELECT * FROM SiteTree_Live st, SolrSearchPage_Live ssp WHERE st.ID = ssp.ID');
$queryCount = $query->numRecords();
$writeCount = 0;
foreach ($query as $results) {
$searchPage = ExtensibleSearchPage::create();
$searchPage->SearchEngine = 'SolrSearch';
// Migrate the key site tree and solr search fields across.
$fields = array('ParentID', 'URLSegment', 'Title', 'MenuTitle', 'Content', 'ShowInMenus', 'ShowInSearch', 'Sort', 'ResultsPerPage', 'SortBy', 'BoostFieldsValue', 'SearchOnFieldsValue', 'SearchTypeValue', 'StartWithListing', 'QueryType', 'ListingTemplateID', 'FilterFieldsValue', 'MinFacetCount', 'FacetQueriesValue', 'FacetMappingValue', 'CustomFacetFieldsValue', 'FacetFieldsValue', 'BoostMatchFieldsValue');
foreach ($fields as $fname) {
if (isset($results[$fname])) {
$searchPage->{$fname} = $results[$fname];
}
}
// This field name no longer matches the original.
if ($results['SortDir']) {
$searchPage->SortDirection = $results['SortDir'];
}
if (isset($relationships[$results['ID']])) {
$searchPage->SearchTrees()->add($relationships[$results['ID']]);
}
// Attempt to publish these new pages.
$searchPage->doPublish();
if ($searchPage->ID) {
echo "<strong>{$results['ID']}</strong> Published<br>";
$writeCount++;
}
$created[] = $results['ID'];
}
// Confirm that the current user had permission to publish these new pages.
$this->checkPermissions($queryCount, $writeCount);
// Migrate any remaining draft pages.
$query = DB::query('SELECT * FROM SiteTree st, SolrSearchPage ssp WHERE st.ID = ssp.ID');
$queryCount = $query->numRecords();
$writeCount = 0;
foreach ($query as $results) {
// Make sure this search page doesn't already exist.
if (!in_array($results['ID'], $created)) {
$searchPage = ExtensibleSearchPage::create();
$searchPage->SearchEngine = 'SolrSearch';
// Migrate the key site tree and solr search fields across.
$searchPage->ParentID = $results['ParentID'];
$searchPage->URLSegment = $results['URLSegment'];
$searchPage->Title = $results['Title'];
$searchPage->MenuTitle = $results['MenuTitle'];
$searchPage->Content = $results['Content'];
$searchPage->ShowInMenus = $results['ShowInMenus'];
$searchPage->ShowInSearch = $results['ShowInSearch'];
$searchPage->Sort = $results['Sort'];
$searchPage->ResultsPerPage = $results['ResultsPerPage'];
$searchPage->SortBy = $results['SortBy'];
$searchPage->SortDirection = $results['SortDir'];
$searchPage->QueryType = $results['QueryType'];
$searchPage->StartWithListing = $results['StartWithListing'];
$searchPage->SearchTypeValue = $results['SearchTypeValue'];
$searchPage->SearchOnFieldsValue = $results['SearchOnFieldsValue'];
$searchPage->BoostFieldsValue = $results['BoostFieldsValue'];
$searchPage->BoostMatchFieldsValue = $results['BoostMatchFieldsValue'];
$searchPage->FacetFieldsValue = $results['FacetFieldsValue'];
$searchPage->CustomFacetFieldsValue = $results['CustomFacetFieldsValue'];
$searchPage->FacetMappingValue = $results['FacetMappingValue'];
$searchPage->FacetQueriesValue = $results['FacetQueriesValue'];
$searchPage->MinFacetCount = $results['MinFacetCount'];
$searchPage->FilterFieldsValue = $results['FilterFieldsValue'];
$searchPage->ListingTemplateID = $results['ListingTemplateID'];
if (isset($relationships[$results['ID']])) {
$searchPage->SearchTrees()->add($relationships[$results['ID']]);
}
$searchPage->write();
if ($searchPage->ID) {
echo "<strong>{$results['ID']}</strong> Saved<br>";
$writeCount++;
}
} else {
$writeCount++;
}
}
// Confirm that the current user had permission to write these new pages.
$this->checkPermissions($queryCount, $writeCount);
// Remove the previous search page tables, as they are now obsolete (and may not be marked as such).
$remove = array('SiteTree', 'SiteTree_Live', 'Page', 'Page_Live');
//.........这里部分代码省略.........
示例14: getDateJoin
public function getDateJoin()
{
$join = "LEFT JOIN `CalendarDateTime` ON `CalendarDateTime`.EventID = `CalendarEvent`.ID";
if (is_subclass_of($this->getEventDateTimeObject(), "CalendarDateTime")) {
$parents = array_reverse(ClassInfo::ancestry($this->getEventDateTimeClass()));
foreach ($parents as $class) {
if (ClassInfo::hasTable($class)) {
if ($class == "CalendarDateTime") {
break;
}
$join .= " LEFT JOIN `{$class}` ON `{$class}`.ID = `CalendarDateTime`.ID";
}
}
}
return $join;
}
示例15: isDatabaseReady
/**
* Determine if the DB is ready to use.
*
* @return bool
* @throws Exception
*/
protected function isDatabaseReady()
{
// Such as during setup of testsession prior to DB connection.
if (!DB::isActive()) {
return false;
}
// If we have a DB of the wrong type then complain
if (!DB::getConn() instanceof MySQLDatabase) {
throw new Exception('HybridSessionStore currently only works with MySQL databases');
}
// Prevent freakout during dev/build
return ClassInfo::hasTable('HybridSessionDataObject');
}