/** * Migrate up * * @access public */ public function up() { $db = Database::get(); $db->query(' CREATE TABLE `email` ( `id` int(11) NOT NULL AUTO_INCREMENT, `language_id` int(11) NOT NULL, `email_type_id` int(11) NOT NULL, `subject` varchar(255) COLLATE utf8_unicode_ci NOT NULL, `text` text COLLATE utf8_unicode_ci NOT NULL, PRIMARY KEY (`id`), KEY `language_id` (`language_id`), KEY `email_type_id` (`email_type_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; ', []); $db->query(' CREATE TABLE `email_type` ( `id` int(11) NOT NULL AUTO_INCREMENT, `name` varchar(128) COLLATE utf8_unicode_ci NOT NULL, `identifier` varchar(128) COLLATE utf8_unicode_ci NOT NULL, `removable` tinyint(1) NOT NULL, `variables` text COLLATE utf8_unicode_ci NOT NULL, PRIMARY KEY (`id`), KEY `short_name` (`short_name`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; ', []); }
/** * Get email by identifier * * @access public * @param string $identifier * @return \Skeleton\Package\Cms\Email\Email */ public static function get_by_identifier($identifier) { $db = Database::get(); $id = $db->get_one('SELECT id FROM email_type WHERE identifier=?', [$identifier]); if ($id === null) { throw new \Exception('Email type not found'); } return self::get_by_id($id); }
/** * Migrate up * * @access public */ public function up() { $db = Database::get(); $db->query("\n\t\t\tCREATE TABLE `supplier` (\n\t\t\t `id` int(11) NOT NULL AUTO_INCREMENT,\n\t\t\t `company` varchar(255) COLLATE utf8_unicode_ci NOT NULL DEFAULT '',\n\t\t\t `phone` varchar(32) COLLATE utf8_unicode_ci NOT NULL DEFAULT '',\n\t\t\t `fax` varchar(32) COLLATE utf8_unicode_ci NOT NULL DEFAULT '',\n\t\t\t `mobile` varchar(32) COLLATE utf8_unicode_ci NOT NULL,\n\t\t\t `email` varchar(64) COLLATE utf8_unicode_ci NOT NULL DEFAULT '',\n\t\t\t `street` varchar(255) COLLATE utf8_unicode_ci NOT NULL DEFAULT '',\n\t\t\t `housenumber` varchar(32) COLLATE utf8_unicode_ci NOT NULL,\n\t\t\t `city` varchar(255) COLLATE utf8_unicode_ci NOT NULL DEFAULT '',\n\t\t\t `zip` varchar(10) COLLATE utf8_unicode_ci NOT NULL,\n\t\t\t `country_id` int(11) NOT NULL DEFAULT '0',\n\t\t\t `vat` varchar(20) COLLATE utf8_unicode_ci NOT NULL DEFAULT '',\n\t\t\t `website` varchar(128) COLLATE utf8_unicode_ci NOT NULL,\n\t\t\t `created` datetime NOT NULL,\n\t\t\t `updated` datetime DEFAULT NULL,\n\t\t\t PRIMARY KEY (`id`),\n\t\t\t KEY `country_id` (`country_id`)\n\t\t\t) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;\n\t\t", []); $db->query("\n\t\t\tCREATE TABLE `object_supplier` (\n\t\t\t `id` int(11) NOT NULL AUTO_INCREMENT,\n\t\t\t `supplier_id` int(11) NOT NULL,\n\t\t\t `object_classname` varchar(128) NOT NULL,\n\t\t\t `object_id` int(11) NOT NULL,\n\t\t\t PRIMARY KEY (`id`)\n\t\t\t) ENGINE=InnoDB DEFAULT CHARSET=utf8;\n\t\t", []); $db->query("\n\t\t\tCREATE TABLE `purchase_order` (\n\t\t\t `id` int(11) NOT NULL AUTO_INCREMENT,\n\t\t\t `created` datetime NOT NULL,\n\t\t\t `supplier_id` int(11) NOT NULL,\n\t\t\t `delivered` tinyint(4) NOT NULL,\n\t\t\t `canceled` tinyint(4) NOT NULL,\n\t\t\t `comments` text NOT NULL,\n\t\t\t PRIMARY KEY (`id`)\n\t\t\t) ENGINE=InnoDB DEFAULT CHARSET=utf8;\n\t\t", []); $db->query("\n\t\t\tCREATE TABLE `purchase_order_item` (\n\t\t\t `id` int(11) NOT NULL AUTO_INCREMENT,\n\t\t\t `purchase_order_id` int(11) NOT NULL,\n\t\t\t `stock_object_classname` varchar(128) NOT NULL,\n\t\t\t `stock_object_id` int(11) NOT NULL,\n\t\t\t `price` decimal(10,2) NOT NULL,\n\t\t\t `amount` int(11) NOT NULL,\n\t\t\t `delivered` int(11) NOT NULL,\n\t\t\t PRIMARY KEY (`id`)\n\t\t\t) ENGINE=InnoDB DEFAULT CHARSET=utf8;\n\t\t", []); $db->query("\n\t\t\tCREATE TABLE `product_stock` (\n\t\t\t `id` int(11) NOT NULL AUTO_INCREMENT,\n\t\t\t `stock_object_classname` varchar(64) NOT NULL,\n\t\t\t `stock_object_id` int(11) NOT NULL,\n\t\t\t `trigger_object_classname` varchar(64) NOT NULL,\n\t\t\t `trigger_object_id` int(11) NOT NULL,\n\t\t\t `total` int(11) NOT NULL,\n\t\t\t `movement` int(11) NOT NULL,\n\t\t\t `created` datetime NOT NULL,\n\t\t\t `comment` varchar(128) NOT NULL,\n\t\t\t PRIMARY KEY (`id`)\n\t\t\t) ENGINE=InnoDB DEFAULT CHARSET=utf8;\n\t\t", []); }
/** * Bootstrap * * @access public */ public static function boot() { /** * Set the root path */ $root_path = realpath(dirname(__FILE__) . '/../..'); /** * Register the autoloader from Composer */ require_once $root_path . '/lib/external/packages/autoload.php'; /** * Get the config */ if (!file_exists($root_path . '/config/Config.php')) { echo 'Please create your Config.php file' . "\n"; exit(1); } require_once $root_path . '/config/Config.php'; $config = Config::get(); /** * Register the autoloader */ $autoloader = new \Skeleton\Core\Autoloader(); $autoloader->add_include_path($root_path . '/lib/model/'); $autoloader->add_include_path($root_path . '/lib/base/'); $autoloader->register(); /** * Initialize the database */ $database = \Skeleton\Database\Database::get($config->database, true); /** * Initialize the application directory */ \Skeleton\Core\Config::$application_dir = $root_path . '/app/'; /** * Initialize the error handler */ \Skeleton\Error\Config::$debug = true; \Skeleton\Error\Handler::enable(); /** * Initialize tmp directory */ \Skeleton\Core\Config::$tmp_dir = $root_path . '/tmp/'; /** * Initialize the translations */ \Skeleton\I18n\Config::$po_directory = $root_path . '/po/'; \Skeleton\I18n\Config::$cache_directory = \Skeleton\Core\Config::$tmp_dir . 'languages/'; /** * Initialize the template caching path */ \Skeleton\Template\Twig\Config::$cache_directory = \Skeleton\Core\Config::$tmp_dir . 'twig/'; /** * Set the migration path */ \Skeleton\Database\Migration\Config::$migration_directory = $root_path . '/migrations/'; }
/** * Migrate up * * @access public */ public function up() { $db = Database::get(); $table = File::trait_get_database_table(); $tables = $db->get_column("SHOW TABLES LIKE '" . $table . "'", []); if (count($tables) == 0) { $db->query("\n\t\t\t\tCREATE TABLE IF NOT EXISTS `" . $table . "` (\n\t\t\t\t `id` int(11) unsigned NOT NULL AUTO_INCREMENT,\n\t\t\t\t `name` varchar(128) COLLATE utf8_unicode_ci NOT NULL,\n\t\t\t\t `unique_name` varchar(128) COLLATE utf8_unicode_ci NOT NULL,\n\t\t\t\t `md5sum` varchar(128) COLLATE utf8_unicode_ci NOT NULL,\n\t\t\t\t `mime_type` varchar(128) COLLATE utf8_unicode_ci NOT NULL,\n\t\t\t\t `size` int(11) NOT NULL,\n\t\t\t\t `created` datetime NOT NULL,\n\t\t\t\t `deleted` datetime NOT NULL,\n\t\t\t\t\tPRIMARY KEY (`id`)\n\t\t\t\t) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1 ;\n\t\t\t", []); } }
/** * Get for Skeleton\Package\Stock\Object * * @access public * @param Skeleton\Package\Stock\Object $object * @return Skeleton\Package\Stock\Supplier $supplier */ public static function get_by_object(\Skeleton\Package\Stock\Object $object) { $db = Database::get(); $id = $db->get_one('SELECT id FROM object_supplier WHERE object_classname=? AND object_id=?', [get_class($object), $object->id]); if ($id === null) { throw new \Exception('No object_supplier found'); } return self::get_by_id($id); }
/** * tostring * * @access public * @return string $condition */ public function __toString() { $db = Database::get(); $join = 'LEFT OUTER JOIN ' . $db->quote_identifier($this->remote_table) . ' on (' . $db->quote_identifier($this->remote_table . '.' . $this->remote_id) . ' = ' . $db->quote_identifier($this->local_field); foreach ($this->conditions as $condition) { $join .= ' AND ' . $condition; } $join .= ')' . "\n"; return $join; }
/** * Get by Object * * @access public * @param mixed $object */ public static function get_by_object($object) { $db = Database::get(); $classname = get_class($object); $ids = $db->get_col('SELECT id FROM log WHERE classname=? AND object_id=? ORDER BY id DESC LIMIT 50', [$classname, $object->id]); $logs = []; foreach ($ids as $id) { $logs[] = self::get_by_id($id); } return $logs; }
/** * Get grouped * * @access public * @return array $countries */ public static function get_grouped() { $db = Database::get(); $db_countries = $db->get_all('SELECT * FROM country WHERE european=1 ORDER BY name ASC', []); $countries = ['european' => [], 'rest' => []]; foreach ($db_countries as $db_country) { $country = new self(); $country->id = $db_country['id']; $country->details = $db_country; $countries['european'][] = $country; } $db_countries = $db->get_all('SELECT * FROM country WHERE european=0 ORDER BY name ASC', []); foreach ($db_countries as $db_country) { $country = new self(); $country->id = $db_country['id']; $country->details = $db_country; $countries['rest'][] = $country; } return $countries; }
/** * Migrate up * * @access public */ public function up() { $table = File::trait_get_database_table(); $db = Database::get(); $ids = $db->get_column('SELECT id FROM ' . $table, []); foreach ($ids as $id) { $file = File::get_by_id($id); $old_path = $this->get_old_path($file); if (!file_exists($old_path)) { continue; } $new_path = $file->get_path(); // create directory if not exist $pathinfo = pathinfo($new_path); if (!is_dir($pathinfo['dirname'])) { mkdir($pathinfo['dirname'], 0755, true); } rename($old_path, $new_path); } /** * Run this to cleanup empty directories */ // echo 'find ' . $path . ' -type d -empty -delete'; }
/** * Migrate up * * @access public */ public function up() { $db = Database::get(); $db->query("\n\t\t\tCREATE TABLE IF NOT EXISTS `transaction` (\n\t\t\t\t`id` int(11) NOT NULL AUTO_INCREMENT,\n\t\t\t\t`classname` varchar(100) COLLATE utf8_unicode_ci NOT NULL,\n\t\t\t\t`created` datetime NOT NULL,\n\t\t\t\t`scheduled_at` datetime NOT NULL,\n\t\t\t\t`executed_at` datetime NOT NULL,\n\t\t\t\t`data` text COLLATE utf8_unicode_ci NOT NULL,\n\t\t\t\t`completed` tinyint(4) NOT NULL,\n\t\t\t\t`failed` tinyint(4) NOT NULL,\n\t\t\t\t`locked` tinyint(4) NOT NULL,\n\t\t\t\t`frozen` tinyint(4) NOT NULL,\n\t\t\t\tPRIMARY KEY (`id`)\n\t\t\t\t) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;\n\t\t"); $db->query("\n\t\t\tCREATE TABLE IF NOT EXISTS `transaction_log` (\n\t\t\t\t`id` int(11) NOT NULL AUTO_INCREMENT,\n\t\t\t\t`transaction_id` int(11) NOT NULL,\n\t\t\t\t`created` datetime NOT NULL,\n\t\t\t\t`output` longtext COLLATE utf8_unicode_ci NOT NULL,\n\t\t\t\t`failed` tinyint(4) NOT NULL,\n\t\t\t\t`exception` longtext COLLATE utf8_unicode_ci NOT NULL,\n\t\t\t\tPRIMARY KEY (`id`),\n\t\t\t\tKEY `transaction_id` (`transaction_id`),\n\t\t\t\tKEY `created` (`created`)\n\t\t\t) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;\n\t\t"); }
/** * tostring * * @access public * @return string $condition */ public function __toString() { $db = Database::get(); if ($this->comparison == 'IN') { if (is_array($this->value[0])) { $list = implode($this->value[0], ', '); } else { $list = $this->value; } return $db->quote_identifier($this->local_field) . ' IN (' . $list . ')' . "\n\t"; } elseif ($this->comparison == 'BETWEEN') { return $db->quote_identifier($this->local_field) . ' BETWEEN ' . $db->quote($this->value[0]) . ' AND ' . $db->quote($this->value[1]) . "\n\t"; } elseif (is_array($this->value)) { $where = '(0'; foreach ($this->value as $field) { $where .= ' OR ' . $db->quote_identifier($this->local_field) . ' ' . $this->comparison . ' ' . $db->quote($field); } $where .= ') '; return $where; } else { return $db->quote_identifier($this->local_field) . ' ' . $this->comparison . ' ' . $db->quote($this->value) . ' ' . "\n\t"; } }
/** * get_by_delivery_deliverable * * @access public * @param Delivery $delivery * @param Deliverable $deliverable * @return array $delivery_items */ public static function get_by_delivery_deliverable(Delivery $delivery, \Skeleton\Package\Delivery\Deliverable $deliverable) { $db = Database::get(); $ids = $db->get_column('SELECT id FROM delivery_item WHERE delivery_id=? AND deliverable_object_classname=? AND deliverable_object_id=?', [$delivery->id, get_class($deliverable), $deliverable->id]); $objects = []; foreach ($ids as $id) { $objects[] = self::get_by_id($id); } return $objects; }
/** * Get backorder * * @access public * @param \Skeleton\Package\Stock\Object $object * @return array $purchase_order_items */ public static function get_backorder(\Skeleton\Package\Stock\Object $object) { $db = Database::get(); $ids = $db->get_column('SELECT id FROM purchase_order_item WHERE stock_object_id=? AND stock_object_classname=? AND amount != delivered', [$object->id, get_class($object)]); $purchase_order_items = []; foreach ($ids as $id) { $purchase_order_items[] = self::get_by_id($id); } return $purchase_order_items; }
/** * Get expired files * * @access public * @return array File $items */ public static function get_expired() { $db = \Skeleton\Database\Database::get(); $ids = $db->get_column('SELECT id FROM file WHERE expiration_date IS NOT NULL AND expiration_date < NOW()'); $items = []; foreach ($ids as $id) { $items[] = self::get_by_id($id); } return $items; }
/** * trait_get_database_config_name: finds out which database name we need to get * * @access private * @return Database $database */ private static function trait_get_database() { if (property_exists(get_class(), 'class_configuration') and isset(self::$class_configuration['database_config_name'])) { $db = Database::get(self::$class_configuration['database_config_name']); } else { $db = Database::get(); } return $db; }
/** * Migrate up * * @access public */ public function up() { $db = Database::get(); $db->query(' CREATE TABLE `delivery` ( `id` int(11) NOT NULL AUTO_INCREMENT, `trigger_object_classname` varchar(64) COLLATE utf8_unicode_ci NOT NULL, `trigger_object_id` int(11) NOT NULL, `recipient_object_classname` varchar(64) COLLATE utf8_unicode_ci NOT NULL, `recipient_object_id` int(11) NOT NULL, `courier_object_classname` varchar(64) COLLATE utf8_unicode_ci NOT NULL, `courier_object_id` int(11) NOT NULL, `created` datetime NOT NULL, `customer_contact_id` int(11) NOT NULL, `shipped` tinyint(4) NOT NULL, `shipping_method_type_id` int(11) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; ', []); $db->query(' CREATE TABLE `delivery_item` ( `id` int(11) NOT NULL AUTO_INCREMENT, `delivery_id` int(11) NOT NULL, `deliverable_object_classname` varchar(64) NOT NULL, `deliverable_object_id` int(11) NOT NULL, `shipment_item_id` int(11) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1; ', []); $db->query(' CREATE TABLE `shipment` ( `id` int(11) NOT NULL AUTO_INCREMENT, `delivery_id` int(11) NOT NULL, `created` datetime NOT NULL, `delivered` tinyint(4) NOT NULL, `company` varchar(255) COLLATE utf8_unicode_ci NOT NULL, `firstname` varchar(64) COLLATE utf8_unicode_ci NOT NULL, `lastname` varchar(64) COLLATE utf8_unicode_ci NOT NULL, `street` varchar(255) COLLATE utf8_unicode_ci NOT NULL, `housenumber` varchar(32) COLLATE utf8_unicode_ci NOT NULL, `line1` varchar(64) COLLATE utf8_unicode_ci NOT NULL, `line2` varchar(64) COLLATE utf8_unicode_ci NOT NULL, `line3` varchar(64) COLLATE utf8_unicode_ci NOT NULL, `zip` varchar(10) COLLATE utf8_unicode_ci NOT NULL, `city` varchar(255) COLLATE utf8_unicode_ci NOT NULL, `phone` varchar(32) COLLATE utf8_unicode_ci NOT NULL, `fax` varchar(32) COLLATE utf8_unicode_ci NOT NULL, `email` varchar(64) COLLATE utf8_unicode_ci NOT NULL, `country_id` int(11) NOT NULL, `vat` varchar(20) COLLATE utf8_unicode_ci NOT NULL, `courier_object_classname` varchar(64) COLLATE utf8_unicode_ci NOT NULL, `courier_object_id` int(11) NOT NULL, `weight` decimal(10,3) NOT NULL, `label_file_id` int(11) NOT NULL, `courier_data` text COLLATE utf8_unicode_ci NOT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; ', []); $db->query(' CREATE TABLE `shipment_item` ( `id` int(11) NOT NULL AUTO_INCREMENT, `shipment_id` int(11) NOT NULL, `delivery_item_id` int(11) NOT NULL, `weight` decimal(10,3) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1; ', []); }
/** * Get undelivered * * @access public * @return array $undelivered */ public static function get_undelivered() { $db = Database::get(); $ids = $db->get_column('SELECT id FROM shipment WHERE delivered=0', []); $objects = []; foreach ($ids as $id) { $objects[] = self::get_by_id($id); } return $objects; }
/** * Get last by object * * @access public * @param \Skeleton\Package\Stock\Object $object * @return \Skeleton\Package\Stock $stock */ public static function get_last_by_object(\Skeleton\Package\Stock\Object $object) { $db = Database::get(); $id = $db->get_one('SELECT id FROM product_stock WHERE stock_object_classname=? AND stock_object_id=? ORDER BY created DESC LIMIT 1', [get_class($object), $object->id]); if ($id === null) { throw new \Exception('No product_stock found'); } return self::get_by_id($id); }
/** * Migrate up * * @access public */ public function up() { $db = Database::get(); $db->query("ALTER TABLE `transaction` DROP `executed_at`;"); $db->query("ALTER TABLE `transaction` ADD `recurring` tinyint(4) NOT NULL AFTER `data`;"); }
/** * Get by trigger * * @access public * @param Object $trigger * @return Delivery $delivery */ public static function get_by_trigger($trigger) { $db = \Skeleton\Database\Database::get(); $id = $db->get_one('SELECT id FROM delivery WHERE trigger_object_classname=? AND trigger_object_id=?', [get_class($trigger), $trigger->id]); if ($id === null) { throw new \Exception('No Delivery found for trigger ' . get_class($trigger) . ' ' . $trigger->id); } return self::get_by_id($id); }