public function __construct($db, $table) { /* CLI case */ defined('APPLICATION_ENV') || define('APPLICATION_ENV', 'production'); $this->esEnabled = Config::get('es.enabled', true); $this->db = $db; $this->table = $table; $this->setEnv(); $path = $this->dirStore(); if (!is_dir($path . DS . 'dbjson')) { umask(00); File::mkdir($path . DS . 'dbjson', 0777, true); } if (!is_dir($path . DS . 'dbjson' . DS . Inflector::lower($this->db . '_' . $this->getEnv()))) { umask(00); File::mkdir($path . DS . 'dbjson' . DS . Inflector::lower($this->db . '_' . $this->getEnv()), 0777, true); } $this->dir = $path . DS . 'dbjson' . DS . Inflector::lower($this->db . '_' . $this->getEnv()) . DS . Inflector::lower($this->table); if (!is_dir($this->dir)) { umask(00); File::mkdir($this->dir, 0777, true); } if (true === $this->cacheEnabled) { $this->getAge(); } $this->facade(); if (false === CLI) { $this->session = Session::instance($this); } }
public function __construct() { $args = func_get_args(); $path = STORAGE_PATH; // $path = isAke(get_defined_constants(), 'STORAGE_PATH', false); if (0 == count($args)) { return; } elseif (2 == count($args)) { list($db, $table) = $args; } elseif (3 == count($args)) { list($db, $table, $path) = $args; } if (false === $path) { throw new Exception("You must provide a path in third argument of this method."); } if (!is_dir($path . DS . 'dbjson')) { umask(00); File::mkdir($path . DS . 'dbjson', 0777, true); } $this->dir = $path . DS . 'dbjson' . DS . Inflector::lower($db) . DS . Inflector::lower($table); if (!is_dir($path . DS . 'dbjson' . DS . Inflector::lower($db))) { umask(00); File::mkdir($path . DS . 'dbjson' . DS . Inflector::lower($db), 0777, true); } if (!is_dir($path . DS . 'dbjson' . DS . Inflector::lower($db) . DS . Inflector::lower($table))) { umask(00); File::mkdir($path . DS . 'dbjson' . DS . Inflector::lower($db) . DS . Inflector::lower($table), 0777, true); } $changeFile = $this->dir . DS . 'change'; if (!File::exists($changeFile)) { File::put($changeFile, ''); } $this->db = $db; $this->table = $table; }
public function model($data = []) { $view = false; $db = $this->db; $table = $this->table; $modelFile = APPLICATION_PATH . DS . 'models' . DS . 'Mysql' . DS . 'models' . DS . Inflector::lower($db) . DS . ucfirst(Inflector::lower($table)) . '.php'; if (!is_dir(APPLICATION_PATH . DS . 'models' . DS . 'Mysql')) { File::mkdir(APPLICATION_PATH . DS . 'models' . DS . 'Mysql'); } if (!is_dir(APPLICATION_PATH . DS . 'models' . DS . 'Mysql' . DS . 'models')) { File::mkdir(APPLICATION_PATH . DS . 'models' . DS . 'Mysql' . DS . 'models'); } if (!is_dir(APPLICATION_PATH . DS . 'models' . DS . 'Mysql' . DS . 'models' . DS . Inflector::lower($db))) { File::mkdir(APPLICATION_PATH . DS . 'models' . DS . 'Mysql' . DS . 'models' . DS . Inflector::lower($db)); } if (!File::exists($modelFile)) { File::put($modelFile, str_replace('##class##', ucfirst(Inflector::lower($db)) . ucfirst(Inflector::lower($table)) . 'SQLModel', File::read(__DIR__ . DS . 'dbModel.tpl'))); } $class = '\\Thin\\' . ucfirst(Inflector::lower($db)) . ucfirst(Inflector::lower($table)) . 'SQLModel'; if (!class_exists($class)) { require_once $modelFile; } $model = $this; if (true === $view) { $model = self::instance($db, $table); } return new $class($model, $data); }
public function __construct($db) { $this->orm = $db; $this->db = $db->db(); $this->table = $db->table(); $dir = Config::get('dir.blizz.store', session_save_path()); if (!is_dir($dir)) { File::mkdir($dir); } $dir .= DS . Inflector::urlize(Inflector::uncamelize($this->db)); if (!is_dir($dir)) { File::mkdir($dir); } $this->dir = $dir . DS . Inflector::urlize(Inflector::uncamelize($this->table)); if (!is_dir($this->dir)) { File::mkdir($this->dir); } $file = $this->dir . DS . 'data.db'; $new = false; if (!is_file($file)) { File::create($file); $new = true; File::put($this->dir . DS . 'age.blizz', ''); } $link = new SQLite3($file); Now::set("blizz.link.{$this->db}.{$this->table}", $link); if ($new) { $this->init(); } }
public function __construct($ns = 'core.cache') { if (!is_dir(STORAGE_PATH . DS . 'kit')) { File::mkdir(STORAGE_PATH . DS . 'kit'); } $file = STORAGE_PATH . DS . 'kit' . DS . $ns . '.db'; $this->lite = new SQLite3($file); $q = "CREATE TABLE IF NOT EXISTS content (k VARCHAR PRIMARY KEY, v, ts);"; $this->raw($q); }
public function __construct($ns = 'core.cache') { $dir = Conf::get('dir.nosql.store', STORAGE_PATH . DS . 'nosql'); if (!is_dir($dir)) { File::mkdir($dir); } $this->dir = $dir . DS . $ns; if (!is_dir($this->dir)) { File::mkdir($this->dir); } }
public function model($data = []) { $db = $this->db; $table = $this->table; $modelFile = APPLICATION_PATH . DS . 'models' . DS . 'Fast' . DS . 'models' . DS . Inflector::lower($db) . DS . ucfirst(Inflector::lower($table)) . '.php'; if (!is_dir(APPLICATION_PATH . DS . 'models' . DS . 'Fast' . DS . 'models' . DS . Inflector::lower($db))) { File::mkdir(APPLICATION_PATH . DS . 'models' . DS . 'Fast' . DS . 'models' . DS . Inflector::lower($db)); } if (!File::exists($modelFile)) { File::put($modelFile, str_replace('##class##', ucfirst(Inflector::lower($db)) . ucfirst(Inflector::lower($table)) . 'ModelFast', File::read(__DIR__ . DS . 'dbModel.tpl'))); } $class = '\\Thin\\' . ucfirst(Inflector::lower($db)) . ucfirst(Inflector::lower($table)) . 'ModelFast'; if (!class_exists($class)) { require_once $modelFile; } $model = $this; return new $class($model, $data); }
public function __construct($db = null, $table = null) { $this->db = is_null($db) ? SITE_NAME : $db; $this->table = is_null($table) ? 'core' : $table; $this->store = Config::get('dir.flight.store'); $this->db = Inflector::urlize($this->db, ''); $this->table = Inflector::urlize($this->table, ''); if (!$this->store) { throw new Exception("You must defined in config a dir store for JDB."); } if (!is_dir($this->store)) { File::mkdir($this->store); } $this->dir = $this->store . DS . $this->db; if (!is_dir($this->dir)) { File::mkdir($this->dir); } $this->ids = $this->dir . DS . 'ids.' . $this->table; if (!file_exists($this->ids)) { File::put($this->ids, 1); } $this->dir .= DS . $this->table; if (!is_dir($this->dir)) { File::mkdir($this->dir); } $this->age = filemtime($this->dir); $this->tuplesDir = $this->dir . DS . 'tuples'; if (!is_dir($this->tuplesDir)) { File::mkdir($this->tuplesDir); } $this->cacheDir = $this->dir . DS . 'cache'; if (!is_dir($this->cacheDir)) { File::mkdir($this->cacheDir); } $this->indicesDir = $this->dir . DS . 'indices'; if (!is_dir($this->indicesDir)) { File::mkdir($this->indicesDir); } $this->relationsDir = $this->dir . DS . 'relations'; if (!is_dir($this->relationsDir)) { File::mkdir($this->relationsDir); } }
public function __construct($db = null, $table = null) { $this->db = is_null($db) ? SITE_NAME : $db; $this->table = is_null($table) ? 'core' : $table; $dir = Config::get('dir.blizz.store', session_save_path()); if (!is_dir($dir)) { File::mkdir($dir); } $dir .= DS . Inflector::urlize(Inflector::uncamelize($this->db)); if (!is_dir($dir)) { File::mkdir($dir); } $this->dir = $dir . DS . Inflector::urlize(Inflector::uncamelize($this->table)); if (!is_dir($this->dir)) { File::mkdir($this->dir); } $store = lib('blizzstore', [$this]); Now::set("blizz.store.{$this->db}.{$this->table}", $store); $this->cursor = lib('blizzcursor', [$this]); }
public function __construct($db, $table) { $path = STORAGE_PATH; if (!is_dir($path . DS . 'dbarray')) { umask(00); File::mkdir($path . DS . 'dbarray', 0777, true); } $this->dir = $path . DS . 'dbarray' . DS . Inflector::lower($db) . DS . Inflector::lower($table); if (!is_dir($path . DS . 'dbarray' . DS . Inflector::lower($db))) { umask(00); File::mkdir($path . DS . 'dbarray' . DS . Inflector::lower($db), 0777, true); } if (!is_dir($path . DS . 'dbarray' . DS . Inflector::lower($db) . DS . Inflector::lower($table))) { umask(00); File::mkdir($path . DS . 'dbarray' . DS . Inflector::lower($db) . DS . Inflector::lower($table), 0777, true); } $age = redis()->get(sha1($this->dir)); if (!strlen($age)) { redis()->set(sha1($this->dir), time() - 24 * 3600); } $this->data(); $this->db = $db; $this->table = $table; }
function makeOfferIn($basket, $universe, $peopleId, $companyId, $companyaddress_id, $delivery = [], $geo = []) { $collection = $collectionPush = []; $company = Model::Company()->find($companyId); $people = Model::People()->find($peopleId); if ($company && $people) { $companyStatus = isAke($company->assoc(), 'status_id', getStatus('UNCHECKED')); $offers = []; if (!empty($basket)) { $i = 0; foreach ($basket as $article) { $dir = realpath(APPLICATION_PATH . DS . '..' . DS . 'public' . DS . 'files' . DS . $universe . DS . 'users' . DS . $peopleId . DS . 'tmp_basket' . DS . $i); if ($dir) { $files = glob($dir . DS . '*'); if (!empty($files)) { foreach ($files as $file) { $article['attach'][] = $file; } } } $market = 0; $item_id = isake($article, 'item_id', 0); if (0 >= $item_id) { $market = isAke($article, 'market', 0); } else { $family = repo('segment')->getFamilyfromItem($item_id); if (!empty($family)) { $market = current($family); $market = isAke($market, 'id', 0); } } if (0 < $market) { unset($article['family']); $offers[$market][] = $article; } $i++; } } if (!empty($offers)) { foreach ($offers as $idMarket => $articles) { $statusOffer = $companyStatus == getStatus('UNCHECKED') ? getStatus('WAIT') : getStatus('OK'); $offer = bigDb('offerin')->create(['global' => true, 'companyaddress_id' => $companyaddress_id, 'delivery_date' => isAke($delivery, 'date', null), 'delivery_type' => isAke($delivery, 'type', null), 'delivery_moment' => isAke($delivery, 'moment', null), 'expiration' => strtotime('+1 month'), 'universe' => $universe, 'market' => (int) $idMarket, 'status_id' => (int) $statusOffer, 'date' => time(), 'zip' => $company->zip, 'people_id' => (int) $peopleId, 'company_id' => $companyId])->save(); foreach ($geo as $g) { bigDb('offeringeo')->create(['offerin_id' => $offer->id, 'type' => isAke($g, 'type'), isAke($g, 'type') . '_id' => isAke($g, 'id'), 'range' => isAke($g, 'range')])->save(); } foreach ($articles as $art) { $options_comp_name = isAke($art, 'options_comp_name'); $options_comp_val = isAke($art, 'options_comp_val'); $item_id = isAke($article, 'item_id', 0); if (0 == $item_id) { $statusOffer = (int) getStatus('ADV'); $offer = $offer->setStatusId($statusOffer)->save(); } if (!empty($options_comp_name) && !empty($options_comp_val)) { /* On cherche les doublons d'option le cas échéant */ list($options_comp_name, $options_comp_val) = cleanOptCompOfferIn($options_comp_name, $options_comp_val); $art['options_comp_name'] = $options_comp_name; $art['options_comp_val'] = $options_comp_val; } $attach = isAke($art, 'attach', []); unset($art['attach']); $art['offerin_id'] = $offer->id; $a = bigDb('articlein')->create($art)->save(); if (!empty($attach)) { $dirOffer = APPLICATION_PATH . DS . '..' . DS . 'public' . DS . 'files' . DS . $universe . DS . 'offer_in'; if (!is_dir($dirOffer)) { File::mkdir($dirOffer); } $dirOffer .= DS . $offer->id; if (!is_dir($dirOffer)) { File::mkdir($dirOffer); } $dirOffer .= DS . $a->id; if (!is_dir($dirOffer)) { File::mkdir($dirOffer); } foreach ($attach as $f) { $tab = explode(DS, $f); $nameAttach = Arrays::last($tab); $newFile = $dirOffer . DS . $nameAttach; File::copy($f, $newFile); File::delete($f); } } } array_push($collection, $offer->assoc()); if ($statusOffer == getStatus('OK')) { array_push($collectionPush, $offer->assoc()); } } } } if (!empty($collectionPush)) { $resellers = lib('bourse')->getResellersByOffer($collectionPush); $employees = lib('bourse')->getEmployeesToNotif($resellers, $collectionPush); lib('bourse')->push($employees); } return $collection; }
public static function generate($model, $overwrite = false) { if (!is_dir(APPLICATION_PATH . DS . 'models' . DS . 'CrudArray')) { File::mkdir(APPLICATION_PATH . DS . 'models' . DS . 'CrudArray', 0777); } $file = APPLICATION_PATH . DS . 'models' . DS . 'CrudArray' . DS . ucfirst(Inflector::camelize($model)) . '.php'; if (!File::exists($file) || $overwrite) { $db = amodel($model); $crud = new Crud($db); File::delete($file); $tplModel = fgc(__DIR__ . DS . 'Model.tpl'); $tplField = fgc(__DIR__ . DS . 'Field.tpl'); $fields = $crud->fields(); $singular = ucfirst($model); $plural = $singular . 's'; $default_order = $crud->pk(); $tplModel = str_replace(array('##singular##', '##plural##', '##default_order##'), array($singular, $plural, $default_order), $tplModel); $fieldsSection = ''; foreach ($fields as $field) { if ($field != $crud->pk()) { $label = substr($field, -3) == '_id' ? ucfirst(str_replace('_id', '', $field)) : ucfirst(Inflector::camelize($field)); $fieldsSection .= str_replace(array('##field##', '##label##'), array($field, $label), $tplField); } } $tplModel = str_replace('##fields##', $fieldsSection, $tplModel); File::put($file, $tplModel); } }
public function getHashFile($hash, $file) { if (!is_dir($this->dir . DS . $hash)) { File::mkdir($this->dir . DS . $hash); } return $this->dir . DS . $hash . DS . $file . '.raw'; }
private function prepare() { $results = $collection = []; $hash = $this->db->getHash(); $this->cursor = $this->db->motor()->getPath() . DS . 'cursors' . DS . $hash; if (is_dir($this->cursor)) { $ageCursor = filemtime($this->cursor . DS . '.'); $ageDb = $this->db->getAge(); if ($ageDb < $ageCursor) { $this->count = count(glob($this->cursor . DS . '*.php', GLOB_NOSORT)); return; } else { File::rmdir($this->cursor); } } File::mkdir($this->db->motor()->getPath() . DS . 'cursors'); File::mkdir($this->db->motor()->getPath() . DS . 'cursors' . DS . $hash); if (empty($this->db->wheres)) { $ids = $this->db->motor()->ids('datas'); foreach ($ids as $id) { $results[$id] = []; } unset($ids); } else { $results = $this->db->results; } $this->count = count($results); if (empty($results)) { File::rmdir($this->cursor); return true; } else { $index = 0; foreach ($results as $id => $row) { if (false !== $id) { $file = $this->cursor . DS . $index . '.php'; $data = $this->db->motor()->read('datas.' . $id); File::put($file, "<?php\nreturn " . var_export($data, 1) . ';'); $index++; } } } }
public function getHashFile($hash, $file) { $hash = 'hash.' . $hash; if (!is_dir($this->dir . DS . $hash)) { File::mkdir($this->dir . DS . $hash); } return $this->dir . DS . $hash . DS . $file . '.store'; }
private function getFile($name) { $path = $this->path; $tab = $tmp = explode('.', $name); $fileName = end($tmp) . '.php'; array_pop($tab); foreach ($tab as $subPath) { $path .= DS . $subPath; if (!is_dir($path)) { File::mkdir($path); } } return $path . DS . $fileName; }
public static function checkDir($type) { $settings = Arrays::exists($type, static::$_settings) ? static::$_settings[$type] : static::defaultConfig($type); $hook = Arrays::exists('checkDir', $settings) ? $settings['checkDir'] : null; static::_hook($hook, func_get_args(), 'before'); $dirName = Inflector::lower($type . 's'); $dir = STORAGE_PATH . DS . 'data' . DS . $dirName; $writeDir = STORAGE_PATH . DS . 'data' . DS . $dirName . DS . 'write'; $readDir = STORAGE_PATH . DS . 'data' . DS . $dirName . DS . 'read'; $versDir = STORAGE_PATH . DS . 'data' . DS . $dirName . DS . 'versions'; $indexDir = STORAGE_PATH . DS . 'data' . DS . $dirName . DS . 'indexes'; File::mkdir($dir, 0777); File::mkdir($writeDir, 0777); File::mkdir($readDir, 0777); File::mkdir($versDir, 0777); File::mkdir($indexDir, 0777); static::_hook($hook, func_get_args(), 'after'); return $dirName; }
public function __destruct() { $file = APPLICATION_PATH . DS . 'models' . DS . 'CrudJson' . DS . ucfirst(Inflector::camelize($this->model->db)) . DS . ucfirst(Inflector::camelize($this->model->table)) . '.php'; if (!is_dir(APPLICATION_PATH . DS . 'models' . DS . 'CrudJson' . DS . ucfirst(Inflector::camelize($this->model->db)))) { File::mkdir(APPLICATION_PATH . DS . 'models' . DS . 'CrudJson' . DS . ucfirst(Inflector::camelize($this->model->db))); } if (!File::exists($file) || $this->replace) { File::delete($file); $tplModel = File::read(__DIR__ . DS . 'Model.tpl'); $tplField = File::read(__DIR__ . DS . 'Field.tpl'); $uniques = isAke($this->indices, 'unique', []); $foreigns = isAke($this->indices, 'foreign', []); $softDelete = true === $this->softDelete ? 'true' : 'false'; $uString = '['; if (count($uniques)) { foreach ($uniques as $unique) { $uString .= "'" . $unique . "'" . ','; } $uString = substr($uString, 0, -1); } $uString .= ']'; $fString = '['; if (count($foreigns)) { foreach ($foreigns as $foreign) { $fString .= "'" . $foreign . "'" . ','; } $fString = substr($fString, 0, -1); } $fString .= ']'; $before_create = $this->getHook('before_create'); $after_create = $this->getHook('after_create'); $before_update = $this->getHook('before_update'); $after_update = $this->getHook('after_update'); $before_read = $this->getHook('before_read'); $after_read = $this->getHook('after_read'); $before_delete = $this->getHook('before_delete'); $after_delete = $this->getHook('after_delete'); $before_list = $this->getHook('before_list'); $after_list = $this->getHook('after_list'); $tplModel = str_replace(['##singular##', '##plural##', '##default_order##', '##soft_delete##', '##foreigns##', '##uniques##', '##before_create##', '##after_create##', '##before_update##', '##after_update##', '##before_read##', '##after_read##', '##before_delete##', '##after_delete##', '##before_list##', '##after_list##'], [$this->singular, $this->plural, $this->order, $softDelete, $fString, $uString, $before_create, $after_create, $before_update, $after_update, $before_read, $after_read, $before_delete, $after_delete, $before_list, $after_list], $tplModel); $fieldsSection = ''; foreach ($this->fields as $field => $infos) { if ($field != 'id') { $label = $this->getSetting($field, 'label', ucfirst($field)); $form_type = $this->getSetting($field, 'form_type', 'text'); $helper = $this->getSetting($field, 'helper', 'false'); $required = $this->getSetting($field, 'required', 'true'); $form_plus = $this->getSetting($field, 'form_plus', 'false'); $length = $this->getSetting($field, 'length', 'false'); $is_listable = $this->getSetting($field, 'is_listable', 'true'); $is_exportable = $this->getSetting($field, 'is_exportable', 'true'); $is_searchable = $this->getSetting($field, 'is_searchable', 'true'); $is_sortable = $this->getSetting($field, 'is_sortable', 'true'); $is_readable = $this->getSetting($field, 'is_readable', 'true'); $is_creatable = $this->getSetting($field, 'is_creatable', 'true'); $is_updatable = $this->getSetting($field, 'is_updatable', 'true'); $is_deletable = $this->getSetting($field, 'is_deletable', 'true'); $content_view = $this->getSetting($field, 'content_view', 'false'); $content_list = $this->getSetting($field, 'content_list', 'false'); $content_search = $this->getSetting($field, 'content_search', 'false'); $content_create = $this->getSetting($field, 'content_create', 'false'); $fieldsSection .= str_replace(['##field##', '##form_type##', '##helper##', '##required##', '##form_plus##', '##length##', '##is_listable##', '##is_exportable##', '##is_searchable##', '##is_sortable##', '##is_readable##', '##is_creatable##', '##is_updatable##', '##is_deletable##', '##content_view##', '##content_list##', '##content_search##', '##content_create##', '##label##'], [$field, $form_type, $helper, $required, $form_plus, $length, $is_listable, $is_exportable, $is_searchable, $is_sortable, $is_readable, $is_creatable, $is_updatable, $is_deletable, $content_view, $content_list, $content_search, $content_create, $label], $tplField); } } $tplModel = str_replace('##fields##', $fieldsSection, $tplModel); File::put($file, $tplModel); } }
public function getFiles($pattern) { $path = APPLICATION_PATH . DS . 'storage' . DS . 'db'; $file = 'caching.' . $pattern; $tab = explode('.', $file); foreach ($tab as $subPath) { $path .= DS . $subPath; if (!is_dir($path)) { File::mkdir($path); } } return glob($path . DS . '*.db'); }
public function hashFile($file, $create = true) { list($prefix, $suffix) = explode('/zelift/dbjson', $this->model->dir, 2); $suffix = str_replace('_production', '_development', $suffix); $hashDir = '/home/gerald/hubic/Web/DB/zelift/dbjson' . $suffix; $id = $this->idFile($file); $hash = sha1($hashDir . $id); $parts = array_slice(str_split($hash, 2), 0, 2); $dir = $this->model->dir; foreach ($parts as $part) { $dir .= DS . $part; if (!is_dir($dir) && $create) { File::mkdir($dir); } } $newFile = $dir . DS . $id . '.row'; return $newFile; }
public function thumb($article, $width = 0, $height = 0, $quality = 60) { if (is_array($article)) { $id = (string) $article['id']; } else { $id = (string) $article; } $img = '/home/php/dev/modules/clippcity/assets/picture/clippcity/' . $id . '.png'; if (!file_exists($img)) { return ''; } $key = sha1(filemtime($img) . $img . $width . $quality); $o = substr($key, 0, 2); $t = substr($key, 2, 2); $d = substr($key, 4, 2); $keyDir = Config::get('app.module.assets') . DS . 'cache' . DS . $o; if (!is_dir($keyDir)) { File::mkdir($keyDir); } $keyDir .= DS . $t; if (!is_dir($keyDir)) { File::mkdir($keyDir); } $keyDir .= DS . $d; if (!is_dir($keyDir)) { File::mkdir($keyDir); } $to = $keyDir . DS . $key . '-' . $width . '-' . $quality . '.jpg'; list($dummy, $dir) = explode('/assets/', $to, 2); $render = '/assets/' . $dir; if (!file_exists($to)) { $dimensions = getimagesize($img); $ratio = $dimensions[0] / $dimensions[1]; if ($width == 0 && $height == 0) { $width = $dimensions[0]; $height = $dimensions[1]; } elseif ($height == 0) { $height = round($width / $ratio); } elseif ($width == 0) { $width = round($height * $ratio); } if ($dimensions[0] > $width / $height * $dimensions[1]) { $dimY = $height; $dimX = round($height * $dimensions[0] / $dimensions[1]); $decalX = ($dimX - $width) / 2; $decalY = 0; } if ($dimensions[0] < $width / $height * $dimensions[1]) { $dimX = $width; $dimY = round($width * $dimensions[1] / $dimensions[0]); $decalY = ($dimY - $height) / 2; $decalX = 0; } if ($dimensions[0] == $width / $height * $dimensions[1]) { $dimX = $width; $dimY = $height; $decalX = 0; $decalY = 0; } $cmd = '/usr/bin/convert -quality ' . $quality . ' -resize ' . $dimX . 'x' . $dimY . ' "' . $img . '" "' . $to . '"'; shell_exec($cmd); } return $render; }
public static function generate($database, $model, $fields = [], $overwrite = false) { if (!is_dir(APPLICATION_PATH . DS . 'models' . DS . 'CrudRaw')) { File::mkdir(APPLICATION_PATH . DS . 'models' . DS . 'CrudRaw'); } $file = APPLICATION_PATH . DS . 'models' . DS . 'CrudRaw' . DS . ucfirst(Inflector::camelize($database)) . DS . ucfirst(Inflector::camelize($model)) . '.php'; if (!is_dir(APPLICATION_PATH . DS . 'models' . DS . 'CrudRaw' . DS . ucfirst(Inflector::camelize($database)))) { File::mkdir(APPLICATION_PATH . DS . 'models' . DS . 'CrudRaw' . DS . ucfirst(Inflector::camelize($database))); } if (!File::exists($file) || $overwrite) { $db = Db::instance($database, $model); $crud = Crud::instance($db); File::delete($file); $tplModel = File::read(__DIR__ . DS . 'Model.tpl'); $tplField = File::read(__DIR__ . DS . 'Field.tpl'); $fields = empty($fields) ? $crud->fields() : $fields; $singular = ucfirst($model); $plural = $singular . 's'; $default_order = $crud->pk(); $tplModel = str_replace(['##singular##', '##plural##', '##default_order##', '##foreigns##', '##uniques##', '##soft_delete##', '##before_create##', '##after_create##', '##before_update##', '##after_update##', '##before_read##', '##after_read##', '##before_delete##', '##after_delete##', '##before_list##', '##after_list##'], [$singular, $plural, $default_order, '[]', '[]', 'false', 'false', 'false', 'false', 'false', 'false', 'false', 'false', 'false', 'false', 'false'], $tplModel); $fieldsSection = ''; foreach ($fields as $field) { if ($field != $crud->pk()) { $label = substr($field, -3) == '_id' ? ucfirst(str_replace('_id', '', $field)) : ucfirst(Inflector::camelize($field)); $fieldsSection .= str_replace(['##field##', '##form_type##', '##helper##', '##required##', '##form_plus##', '##length##', '##is_listable##', '##is_exportable##', '##is_searchable##', '##is_sortable##', '##is_readable##', '##is_creatable##', '##is_updatable##', '##is_deletable##', '##content_view##', '##content_list##', '##content_search##', '##content_create##', '##label##'], [$field, 'text', 'false', 'true', 'false', 'false', 'true', 'true', 'true', 'true', 'true', 'true', 'true', 'true', 'false', 'false', 'false', 'false', $label], $tplField); } } $tplModel = str_replace('##fields##', $fieldsSection, $tplModel); File::put($file, $tplModel); } }
public function refresh() { if (!$this->begin) { if (true === $this->write) { if (!empty($this->toDelete)) { foreach ($this->toDelete as $row) { $id = isAke($row, 'id'); $file = $this->dir . DS . 'id' . DS . $id . '.blazz'; if (!is_dir($this->dir . DS . 'id')) { File::mkdir($this->dir . DS . 'id'); } File::delete($file); foreach ($row as $k => $v) { $file = $this->dir . DS . $k . DS . $id . '.blazz'; if (!is_dir($this->dir . DS . $k)) { File::mkdir($this->dir . DS . $k); } File::delete($file); } $file = $this->dir . DS . $id . '.blazz'; File::delete($file); touch($this->dir . DS . 'age.blazz', time()); } } if (!empty($this->toWrite)) { foreach ($this->toWrite as $row) { $id = isAke($row, 'id'); $id = (int) $id; $file = $this->dir . DS . 'id' . DS . $id . '.blazz'; if (!is_dir($this->dir . DS . 'id')) { File::mkdir($this->dir . DS . 'id'); } File::delete($file); File::put($file, serialize($id)); foreach ($row as $k => $v) { if ($k == 'id') { continue; } if (fnmatch('*_id', $k)) { $v = (int) $v; } if (!is_dir($this->dir . DS . $k)) { File::mkdir($this->dir . DS . $k); } $file = $this->dir . DS . $k . DS . $id . '.blazz'; File::delete($file); File::put($file, serialize($v)); $row[$k] = $v; } $file = $this->dir . DS . $id . '.blazz'; File::delete($file); File::put($file, serialize($row)); touch($this->dir . DS . 'age.blazz', time()); } } $this->cursor = core('cursor', [$this])->reset(); $this->write = false; } } else { throw new Exception("Please commit or rollback your transaction."); } return $this; }
public function makeBackup($database = null) { set_time_limit(0); $database = is_null($database) ? SITE_NAME : $database; $db = $this->getOdm(); $collections = $db->getCollectionNames(); $key = array_search('zelift.ages', $collections); if (strlen($key)) { unset($collections[$key]); } $key = array_search('zelift.counters', $collections); if (strlen($key)) { unset($collections[$key]); } $key = array_search('zelift.tuples', $collections); if (strlen($key)) { unset($collections[$key]); } $key = array_search('zelift.caching', $collections); if (strlen($key)) { unset($collections[$key]); } $key = array_search('zelift.ages', $collections); if (strlen($key)) { unset($collections[$key]); } $i = 0; foreach ($collections as $coll) { $path = \Thin\Config::get('application.backup_dir'); if (!is_dir($path)) { return false; } list($collDb, $collTable) = explode('.', $coll, 2); if ($collDb != $database) { continue; } $path = $path . DS . $collDb; if (!is_dir($path)) { File::mkdir($path); } $path = $path . DS . $collTable; if (!is_dir($path)) { File::mkdir($path); } $model = self::instance($collDb, $collTable); $cursor = $model->cursor(); while ($row = $cursor->fetch()) { if (isset($row['id'])) { $file = $path . DS . $row['id'] . '.json'; File::put($file, json_encode($row)); $i++; } } } $now = date("d_m_Y_H_i_s"); $path = \Thin\Config::get('application.backup_dir', false); $user = \Thin\Config::get('redis.ftp.backup.user', false); $password = \Thin\Config::get('redis.ftp.backup.password', false); $host = \Thin\Config::get('redis.ftp.backup.host', false); if (false !== $path && false !== $user && false !== $password && false !== $host) { $cmd = "cd {$path} && tar cfvz zelift_{$now}.tar.gz {$path}\nlftp -e 'put {$path}/zelift_{$now}.tar.gz; bye' -u \"{$user}\",{$password} {$host}\nrm zelift_{$now}.tar.gz\necho 'done'"; passthru($cmd); } vd($i); dd(Timer::get()); }