Example #1
0
 /**
  * Run one migration .sql file
  * @param string $filename
  * @return $this
  */
 private function runMigrationFile($filename)
 {
     SQL::startTransaction();
     // Force SQL run without errors
     @q(file_get_contents(DIR_MIGRATIONS . $filename));
     SQL::confirmTransaction();
     return $this;
 }
Example #2
0
 private static function combineParamsFromDB($table, array $order_keys)
 {
     // Fields from DB
     $fields = $types = SQL::getFieldsWithAllData($table);
     unset($fields['id']);
     // Sort to match defined order for form
     $sorted = $not_sorted = [];
     foreach ($fields as $k => $v) {
         if (($key = array_search($k, $order_keys)) !== false) {
             $sorted[$key] = $k;
         } else {
             $not_sorted[] = $k;
         }
     }
     ksort($sorted);
     $fields = array_merge($sorted, $not_sorted);
     $params = [];
     foreach ($fields as $v) {
         $field = [];
         $type = $types[$v]['Type'];
         if (strpos($type, 'text') !== false) {
             $field['type'] = 'textarea';
         }
         if (strpos($type, 'enum') !== false) {
             $field['type'] = 'select';
             $field['options'] = SQL::getEnumPairs($table, $types[$v]['Field']);
         }
         $field['name'] = Converter::symb2Ttl($v);
         $params[$v] = $field;
     }
     return $params;
 }
Example #3
0
 public function ensureDbTableStructureIsFresh()
 {
     $source = SQL::getCreateTable($this->getTableName());
     $destination = $this->getCreateTableStatement();
     $sync = new Sync();
     $sync->makeItWork();
     $sql = $sync->getUpdates($source, $destination);
     // Commented - do not auto run migrations, but only show desired changes
     //        if ($sql) {
     //            foreach ($sql as $item) {
     //                q($item);
     //            }
     //        }
     return $sql;
 }
Example #4
0
<?php

use TMCms\DB\SQL;
use TMCms\Log\Errors;
if (!defined('INC')) {
    define('INC', true);
}
if (!defined('MODE')) {
    define('MODE', 'site');
}
if (stripos(USER_AGENT, 'bot') !== false) {
    return;
}
$msg = isset($_GET['msg']) ? $_GET['msg'] : '';
$stack = isset($_GET['stack']) ? $_GET['stack'] : '';
$url = isset($_GET['url']) ? $_GET['url'] : '';
$line = isset($_GET['line']) ? $_GET['line'] : '';
Errors::notify_devs(CFG_DOMAIN . ' JavaScript error', 'Message: ' . $msg . "\nClicks Stack: " . $stack . "\nURL: " . $url . "\nLine: " . $line);
// Write log if DB available
if (!SQL::getInstance()->getConnectionHandler()) {
    return;
}
q('INSERT INTO `cms_error_log` (
    `ts`, `ip_long`, `agent`,
    `type`, `msg`, `file`,
    `line`, `vars`
) VALUES (
    "' . NOW . '", "' . ip2long(IP) . '", "' . USER_AGENT . '",
    "JS", "' . sql_prepare($msg) . '", "' . sql_prepare($url) . '",
    "' . sql_prepare($line) . '", "' . sql_prepare($stack) . '"
)');
Example #5
0
/**
 * @param string $q
 * @return string
 */
function q_value($q)
{
    return SQL::q_value($q);
}
Example #6
0
 /**
  * @return bool table exists
  */
 private function ensureDbTableExists()
 {
     $table = $this->getDbTableName();
     // May be empty
     if ($table == 'm_s') {
         return true;
     }
     $schema = new TableStructure();
     $schema->setTableName($this->getDbTableName());
     $schema->setTableStructure($this->getTableStructure());
     if (!SQL::tableExists($table)) {
         // Create table;
         $schema->createTableIfNotExists();
     }
     // Update structure using auto-created migrations
     //        $schema->ensureDbTableStructureIsFresh(); // This changes a lot of required items, do not use in future
     return true;
 }
Example #7
0
 /**
  * Init all settings
  * @param bool $no_cache fetch data from cache or not
  * @return array
  */
 public function init($no_cache = false)
 {
     $this->bootCacher();
     // From local cache
     if (self::$_cached_settings && is_array(self::$_cached_settings) && !$no_cache) {
         return self::$_cached_settings;
     }
     if ($no_cache) {
         // Force cache invalidation
         self::$_cached_settings = [];
     } else {
         // Get from cache
         self::$_cached_settings = Cacher::getInstance()->getDefaultCacher()->get(self::CACHE_KEY);
     }
     if (!self::$_cached_settings && SQL::tableExists('cms_settings')) {
         // Get from DB
         $settings_collection = new SettingEntityRepository();
         self::$_cached_settings = $settings_collection->getPairs('value', 'name');
         Cacher::getInstance()->getDefaultCacher()->set(self::CACHE_KEY, self::$_cached_settings);
     }
     if (!is_array(self::$_cached_settings)) {
         self::$_cached_settings = [];
     }
     return self::$_cached_settings;
 }
Example #8
0
 public function _order()
 {
     $id = abs((int) $_GET['id']);
     if (!$id) {
         return;
     }
     $entity = $this->getRealEntityInUse($id);
     SQL::order($entity->getId(), $entity->getDbTableName(), $_GET['direct']);
     back();
 }
Example #9
0
 /**
  * @return $this
  */
 public function rollback()
 {
     if (SQL::isTransactionActive()) {
         SQL::cancelTransaction();
     }
     return $this;
 }
 public function __settings_form($data = NULL)
 {
     /** @var CustomSetting $data */
     $form_array = ['title' => $data ? __('Edit custom setting') : __('Add custom setting'), 'data' => $data, 'action' => '?p=' . P . '&do=_add', 'button' => 'Add', 'fields' => ['module' => ['type' => 'datalist', 'options' => ModuleManager::getListOfCustomModuleNames()], 'key' => ['required' => true], 'input_type' => ['options' => SQL::getEnumPairs(ModuleSettings::$tables['settings'], 'input_type')], 'input_options' => ['type' => 'checkbox_list', 'options' => ['editor_wysiwyg' => 'Wysiwyg', 'editor_files' => 'Filemanager', 'editor_pages' => 'Pages', 'require' => 'Required', 'is_digit' => 'Digit', 'alphanum' => 'Alphanumeric', 'url' => 'URL', 'email' => 'email']]]];
     return CmsFormHelper::outputForm(ModuleSettings::$tables['settings'], $form_array);
 }