/** * 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", []); } }
/** * 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'; }
/** * 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(); }
/** * Rotate * * @access public * @param int $degrees */ public function rotate($degrees) { $pdf = new \FPDI(); $pagecount = $pdf->setSourceFile($this->get_path()); for ($i = 1; $i <= $pagecount; $i++) { $templateId = $pdf->importPage($i); $size = $pdf->getTemplateSize($templateId); if ($size['w'] > $size['h']) { $pdf->AddPage('L', [$size['w'], $size['h'], 'Rotate' => $degrees]); } else { $pdf->AddPage('P', [$size['w'], $size['h'], 'Rotate' => $degrees]); } $pdf->useTemplate($templateId); } $pdf->Rotate($degrees); $content = $pdf->Output('ignored', 'S'); $file = \Skeleton\File\File::store('page_' . $i . '.pdf', $content); return $file; }