Beispiel #1
0
 function screen_versions($id)
 {
     if (isset($_POST['save']) && check_admin_referer('drainhole-version_add')) {
         $_POST = stripslashes_deep($_POST);
         $file = DH_File::get($id);
         DH_Version::create($file, $_POST['version'], 0, mktime(0, 0, 0, intval($_POST['month']), intval($_POST['day']), intval($_POST['year'])), $_POST['reason']);
         $this->render_message(__('Your version was added succesfully', 'drain-hole'));
     }
     $file = DH_File::get($id);
     $hole = DH_Hole::get($file->hole_id);
     $pager = new DH_Pager($_GET, $_SERVER['REQUEST_URI'], 'created_at', 'DESC', 'drainhole-versions');
     $versions = DH_Version::get_by_file($id, $pager);
     $this->render_admin('versions', array('file' => $file, 'pager' => $pager, 'versions' => $versions, 'hole' => $hole));
 }
Beispiel #2
0
 function upgrade_from_1()
 {
     global $wpdb;
     // Add columns to drainhole_access: version_id, user_id
     $wpdb->query("ALTER TABLE `{$wpdb->prefix}drainhole_access` ADD `user_id` int UNSIGNED NOT NULL;");
     // Add columns to drainhole_files: name, description, created_at
     $wpdb->query("ALTER TABLE `{$wpdb->prefix}drainhole_files` ADD `name` varchar(150) NOT NULL default '';");
     $wpdb->query("ALTER TABLE `{$wpdb->prefix}drainhole_files` ADD `description` TEXT default NULL;");
     $wpdb->query("ALTER TABLE `{$wpdb->prefix}drainhole_files` ADD\t`version_id` int(11) unsigned NOT NULL;");
     $wpdb->query("ALTER TABLE `{$wpdb->prefix}drainhole_files` ADD `options` mediumtext DEFAULT NULL ;");
     $wpdb->query("ALTER TABLE `{$wpdb->prefix}drainhole_files` ADD `svn` varchar(150) DEFAULT NULL ;");
     $wpdb->query("ALTER TABLE `{$wpdb->prefix}drainhole_access` ADD `version_id` int UNSIGNED NOT NULL DEFAULT '0';");
     // Change columns in drainhole_files for: file
     $wpdb->query("ALTER TABLE `{$wpdb->prefix}drainhole_files` CHANGE `file` `file` varchar(150) NOT NULL default '';");
     $wpdb->query("ALTER TABLE `{$wpdb->prefix}drainhole_files` CHANGE `downloads` `hits` int(10) UNSIGNED NOT NULL DEFAULT '0';");
     $wpdb->query("ALTER TABLE `{$wpdb->prefix}drainhole_holes` CHANGE `role_error_id` `role_error_url` varchar(100) DEFAULT NULL;");
     $files = DH_File::get_all();
     // Remove columns
     $wpdb->query("ALTER TABLE `{$wpdb->prefix}drainhole_files` DROP `version`;");
     $wpdb->query("ALTER TABLE `{$wpdb->prefix}drainhole_files` DROP `force_download`;");
     // Create the first version for each file and link it back to the file
     // Also link all access stats to the latest version
     if (count($files) > 0) {
         foreach ($files as $file) {
             $version = DH_Version::create($file, $file->version, $file->hits, $file->updated_at, __('First version', 'drain-hole'));
             $options = $wpdb->escape(serialize(array('force_download' => $file->force_download)));
             $wpdb->query("UPDATE {$wpdb->prefix}drainhole_files SET version_id='{$version}',options='{$options}' WHERE id='{$file->id}'");
             $wpdb->query("UPDATE {$wpdb->prefix}drainhole_access SET version_id='{$version}' WHERE file_id='{$file->id}'");
         }
     }
 }
Beispiel #3
0
 function create_new_version($version, $branch, $reason, $dontbranch = false, $svnupdate = false)
 {
     global $wpdb;
     $hole = DH_Hole::get($this->hole_id);
     // Branch our copy
     if ($dontbranch === false && $branch) {
         if ($hole && $this->exists($hole)) {
             $target = $this->file($hole, $this->version_id);
             @wp_mkdir_p(dirname($target));
             @copy($this->file($hole), $target);
         }
     }
     // Sort out any SVN business
     if ($this->svn && $svnupdate) {
         $options = get_option('drainhole_options');
         if ($options && isset($options['svn']) && $options['svn']) {
             include dirname(__FILE__) . '/svn.php';
             $svn = new DH_SVN($this->svn, $options['svn']);
             $svn->update($this->file($hole));
             if ($svn->version()) {
                 $version = $svn->version();
             }
         }
     }
     // Store details in a version branch
     if ($dontbranch === false) {
         $version = DH_Version::create($this, $version, $this->hits - DH_Version::total_hits($this->id), '', $reason);
         // Update our details
         $wpdb->query("UPDATE {$wpdb->prefix}drainhole_files SET updated_at=NOW(), version_id='{$version}' WHERE id={$this->id}");
     } else {
         $wpdb->query("UPDATE {$wpdb->prefix}drainhole_version SET version='{$version}', created_at=NOW() WHERE id={$this->version_id}");
     }
     return true;
 }