/**
     * 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;
		', []);
    }
Пример #2
0
 /**
  * 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", []);
 }
Пример #4
0
 /**
  * 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", []);
     }
 }
Пример #5
0
 /**
  * Get last by transaction
  *
  * @access public
  * @param Transaction $transaction
  * @return array $transaction_logs
  */
 public static function get_last_by_transaction(Transaction $transaction)
 {
     $db = Database::Get();
     $id = $db->get_one('SELECT id FROM transaction_log WHERE transaction_id=? ORDER BY created DESC LIMIT 1', [$transaction->id]);
     if ($id === null) {
         throw new \Exception('No transaction_log yet');
     }
     return self::get_by_id($id);
 }
Пример #6
0
 /**
  * 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);
 }
Пример #7
0
 /**
  * Get by name_short
  *
  * @access public
  * @return Language
  * @param string $name_short
  */
 public static function get_by_name_short($name)
 {
     $db = Database::Get();
     $id = $db->get_one('SELECT id FROM language WHERE name_short=?', [$name]);
     if ($id === null) {
         throw new \Exception('No such language');
     }
     return self::get_by_id($id);
 }
Пример #8
0
 /**
  * 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/';
 }
Пример #9
0
 /**
  * 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;
 }
Пример #10
0
 /**
  * Get by Shipment
  *
  * @access public
  * @param Shipment $shipment
  * @return array $shipment_items
  */
 public static function get_by_shipment(Shipment $shipment)
 {
     $db = Database::Get();
     $ids = $db->get_column('SELECT id FROM shipment_item WHERE shipment_id=?', [$shipment->id]);
     $objects = [];
     foreach ($ids as $id) {
         $objects[] = self::get_by_id($id);
     }
     return $objects;
 }
Пример #11
0
 /**
  * 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;
 }
Пример #12
0
 /**
  * Migrate up
  *
  * @access public
  */
 public function up()
 {
     $db = Database::Get();
     $db->query("\n\t\t\tCREATE TABLE IF NOT EXISTS `language` (\n\t\t\t  `id` int(11) NOT NULL AUTO_INCREMENT,\n\t\t\t  `name` varchar(64) COLLATE utf8_unicode_ci NOT NULL DEFAULT '',\n\t\t\t  `name_local` varchar(64) COLLATE utf8_unicode_ci NOT NULL DEFAULT '',\n\t\t\t  `name_short` varchar(2) COLLATE utf8_unicode_ci NOT NULL DEFAULT '',\n\t\t\t  `name_ogone` varchar(255) COLLATE utf8_unicode_ci NOT NULL,\n\t\t\t  PRIMARY KEY (`id`),\n\t\t\t  FULLTEXT KEY `name_short` (`name_short`)\n\t\t\t) ENGINE=MyISAM AUTO_INCREMENT=1 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;\n\t\t", []);
     $db->query("\n\t\t\tINSERT INTO `language` VALUES (1,'English','English','en','en_US'),(2,'French','Français','fr','fr_FR'),(3,'Dutch','Nederlands','nl','nl_NL');\n\t\t", []);
     $db->query("\n\t\t\tCREATE TABLE IF NOT EXISTS `log` (\n\t\t\t  `id` int(11) NOT NULL AUTO_INCREMENT,\n\t\t\t  `user_id` int(11) NOT NULL,\n\t\t\t  `classname` varchar(32) COLLATE utf8_unicode_ci NOT NULL,\n\t\t\t  `object_id` int(11) NOT NULL,\n\t\t\t  `content` text COLLATE utf8_unicode_ci NOT NULL,\n\t\t\t  `created` datetime NOT NULL,\n\t\t\t  PRIMARY KEY (`id`),\n\t\t\t  KEY `classname` (`classname`)\n\t\t\t) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1 ;\n\t\t", []);
     $db->query("\n\t\t\tCREATE TABLE IF NOT EXISTS `file` (\n\t\t\t  `id` int(11) unsigned NOT NULL AUTO_INCREMENT,\n\t\t\t  `name` varchar(255) COLLATE utf8_unicode_ci NOT NULL,\n\t\t\t  `unique_name` varchar(255) COLLATE utf8_unicode_ci NOT NULL,\n\t\t\t  `mime_type` varchar(255) COLLATE utf8_unicode_ci NOT NULL,\n\t\t\t  `size` int(11) NOT NULL,\n\t\t\t  `created` datetime NOT NULL,\n\t\t\t  PRIMARY KEY (`id`)\n\t\t\t) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1 ;\n\t\t", []);
     $db->query("\n\t\t\tCREATE TABLE IF NOT EXISTS `picture` (\n\t\t\t  `id` int(11) NOT NULL AUTO_INCREMENT,\n\t\t\t  `file_id` int(11) NOT NULL,\n\t\t\t  `width` int(11) NOT NULL,\n\t\t\t  `height` int(11) NOT NULL,\n\t\t\t  PRIMARY KEY (`id`),\n\t\t\t  KEY `file_id` (`file_id`)\n\t\t\t) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1 ;\n\t\t", []);
     $db->query("\n\t\t\tCREATE TABLE IF NOT EXISTS `user` (\n\t\t\t  `id` int(11) NOT NULL AUTO_INCREMENT,\n\t\t\t  `firstname` varchar(255) COLLATE utf8_unicode_ci NOT NULL,\n\t\t\t  `lastname` varchar(255) COLLATE utf8_unicode_ci NOT NULL,\n\t\t\t  `email` varchar(255) COLLATE utf8_unicode_ci NOT NULL,\n\t\t\t  `username` varchar(32) COLLATE utf8_unicode_ci NOT NULL,\n\t\t\t  `password` varchar(255) COLLATE utf8_unicode_ci NOT NULL,\n\t\t\t  `admin` tinyint(1) NOT NULL,\n\t\t\t  `created` datetime NOT NULL,\n\t\t\t  PRIMARY KEY (`id`)\n\t\t\t) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1 ;\n\t\t", []);
     $db->query("\n\t\t\tALTER TABLE  `file` ADD  `md5sum` VARCHAR( 32 ) NOT NULL AFTER  `name`;\n\t\t", []);
     $db->query("\n\t\t\tALTER TABLE  `file` DROP  `unique_name`;\n\t\t", []);
     $db->query("\n\t\t\tALTER TABLE  `file` ADD `expiration_date` datetime NULL AFTER `size`;\n\t\t", []);
 }
Пример #13
0
 /**
  * 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';
 }
Пример #15
0
 /**
  * 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;
 }
 /**
  * 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");
 }
Пример #17
0
 /**
  * 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";
     }
 }
Пример #18
0
 /**
  * Get by delivery
  *
  * @access public
  * @param Delivery $delivery
  * @return array $shipments
  */
 public static function get_by_delivery(Delivery $delivery)
 {
     $db = Database::Get();
     $ids = $db->get_column('SELECT id FROM shipment WHERE delivery_id=?', [$delivery->id]);
     $objects = [];
     foreach ($ids as $id) {
         $objects[] = self::get_by_id($id);
     }
     return $objects;
 }
Пример #19
0
 /**
  * Delete the image and its cache
  *
  * @access public
  */
 public function delete()
 {
     foreach (Config::$resize_configurations as $name => $configuration) {
         if (file_exists(Config::$tmp_dir . $name . '/' . $this->id)) {
             unlink(Config::$tmp_dir . $name . '/' . $this->id);
         }
     }
     $db = Database::Get();
     $db->query('DELETE FROM picture WHERE file_id=?', [$this->id]);
     parent::delete();
 }
Пример #20
0
 /**
  * Fetch a user by email
  *
  * @access public
  * @param string $email
  * @return User $user
  */
 public static function get_by_email($email)
 {
     $db = Database::Get();
     $id = $db->get_one('SELECT id FROM user WHERE email = ?', [$email]);
     if ($id === null) {
         throw new \Exception('User not found');
     }
     return self::get_by_id($id);
 }
Пример #21
0
 /**
  * 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;
 }
Пример #22
0
    /**
     * Get runnable transactions
     *
     * @return array
     * @access public
     */
    public static function get_runnable()
    {
        $db = \Skeleton\Database\Database::Get();
        $transactions = [];
        $trans = $db->get_column('
			SELECT id FROM
				(SELECT id, frozen, failed, locked, created FROM transaction WHERE scheduled_at < NOW() AND completed=0) AS transaction
			WHERE 1
			AND frozen = 0
			AND failed = 0
			AND locked = 0
			ORDER BY created');
        foreach ($trans as $id) {
            $transactions[] = self::get_by_id($id);
        }
        return $transactions;
    }
Пример #23
0
 /**
  * Get classnames
  *
  * @access public
  * @return array $classnames
  */
 public static function get_classnames()
 {
     $db = Database::Get();
     $classnames = $db->get_column('SELECT DISTINCT(classname) FROM object_text', array());
     return $classnames;
 }
Пример #24
0
 /**
  * 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);
 }
Пример #25
0
 /**
  * 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;
 }
Пример #26
0
 /**
  * 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;
		', []);
    }
 /**
  * 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`;");
 }
Пример #29
0
 /**
  * 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);
 }