Anonymous Login
2019-07-19 11:30 PDT

View Issue Details Jump to Notes ]
IDProjectCategoryView StatusLast Update
0000741Pending RequestsTaskspublic2014-08-16 18:53
Reporteropto 
Assigned Tocaseydk 
PrioritynormalSeverityminorReproducibilityhave not tried
StatusfeedbackResolutionopen 
Product Version 
Target VersionFixed in Version 
Summary0000741: on import, copy files of template
Descriptionon task import, the code in the forum post does:

iterates all files of the original project

pulls the newest version of each file
copies this into the new project's folder

stores this as file for the new project or task

see http://forums.web2project.net/viewtopic.php?t=3386

Intentionally, only the newest version is copied - to dublicate fewer files in the file system.

If older versions are required, they can be looked up in the original template.
The version string is kept.

Klaus
TagsNo tags attached.
Attached Files

-Relationships
+Relationships

-Notes

~0001720

opto (manager)

Last edited: 2011-03-09 12:27

SOLVED in the forum post

also, is there any way to edit a bug report?

~0001721

opto (manager)

If it might make things easier:

put it into source control, this is a diff:

=== verändert Datei classes/ui.class.php
--- classes/ui.class.php 2011-03-12 10:08:47 +0000
+++ classes/ui.class.php 2011-03-12 12:46:03 +0000
@@ -263,7 +263,23 @@
         return $ts->format($df);
     }
 
- /**
+
+
+ public function convertToUserTZ($datetime = '', $format = 'Y-m-d H:i:s') {
+$userTZ = $this->getPref('TIMEZONE');
+$userTimezone = new DateTimeZone($userTZ);
+
+$systemTimezone = new DateTimeZone('Europe/London');
+
+$ts = new DateTime($datetime, $systemTimezone);
+$ts->setTimezone($userTimezone);
+
+return $ts->format($format);
+}
+
+
+
+/**
     *
     */
     public function convertToSystemTZ($datetime = '', $format = 'Y-m-d H:i:s') {

=== verändert Datei modules/files/files.class.php
--- modules/files/files.class.php 2011-03-12 10:12:56 +0000
+++ modules/files/files.class.php 2011-03-12 12:46:03 +0000
@@ -93,7 +93,65 @@
         return $search;
     }
 
- public static function getFileList(CAppUI $AppUI = null, $company_id, $project_id, $task_id, $category_id) {
+
+
+
+public function load($oid = null, $strip = true) {
+return parent::load($oid, $strip);
+}
+
+public function getNextFileVersionID() {
+$q = new DBQuery;
+$q->addTable('files');
+$q->addQuery('file_version_id');
+$q->addOrder('file_version_id DESC');
+$q->setLimit(1);
+$latest_file_version = $q->loadResult();
+$q->clear();
+return $latest_file_version + 1;
+
+}
+
+public static function getFileListLastVersionOnly(CAppUI $AppUI = null, $company_id, $project_id, $task_id, $category_id) {
+global $AppUI;
+//this query, taken from index_table.php, gives the right latest_id, but the other fields are not those of latest_id
+// for each grouping of file_version_id, latest_id gives the id of the newest file
+$q2 = new DBQuery();
+$q2->addQuery('f.*' . ', max(f.file_id) as latest_id' . ', count(f.file_version) as file_versions, round(max(f.file_version),2) as file_lastversion');
+
+$q2->addQuery('ff.*');
+$q2->addTable('files', 'f');
+$q2->addJoin('file_folders', 'ff', 'ff.file_folder_id = file_folder');
+$q2->addJoin('projects', 'p', 'p.project_id = file_project');
+$q2->addJoin('tasks', 't', 't.task_id = file_task');
+$q2->leftJoin('project_departments', 'project_departments', 'p.project_id = project_departments.project_id OR project_departments.project_id IS NULL');
+$q2->leftJoin('departments', 'departments', 'departments.dept_id = project_departments.department_id OR dept_id IS NULL');
+if (count($allowedProjects)) {
+$q2->addWhere('( ( ' . implode(' AND ', $allowedProjects) . ') OR file_project = 0 )');
+}
+if (count($allowedTasks)) {
+$q2->addWhere('( ( ' . implode(' AND ', $allowedTasks) . ') OR file_task = 0 )');
+}
+
+if ($company_id) {
+$q2->addWhere('project_company = ' . (int)$company_id);
+}
+if ($project_id) {
+$q2->addWhere('file_project = ' . (int)$project_id);
+}
+if ($task_id) {
+$q2->addWhere('file_task = ' . (int)$task_id);
+}
+$q2->addGroup('p.project_id');
+$q2->addGroup('file_version_id DESC');
+return $q2->loadList();
+
+}
+
+
+
+
+ public static function getFileList(CAppUI $AppUI = null, $company_id, $project_id, $task_id, $category_id) {
         global $AppUI;
 
         $q = new w2p_Database_Query();

=== verändert Datei modules/projects/projects.class.php
--- modules/projects/projects.class.php 2011-03-12 10:12:56 +0000
+++ modules/projects/projects.class.php 2011-03-12 12:46:03 +0000
@@ -251,6 +251,11 @@
         // Dependencies array
         $deps = array();
 
+
+ //old index - new index array
+ $newInd = array();
+
+
         // Copy each task into this project and get their deps
         foreach ($tasks as $orig => $void) {
             $objTask = new CTask();
@@ -297,6 +302,9 @@
                 $newTask->updateDependencies($csList);
             } // end of update dependencies
             $result = $newTask->store($AppUI);
+ //remember new/old task id's
+ $newInd[$old_id]=$newTask->task_id;
+
 
             if (is_array($result) && count($result)) {
                 foreach ($result as $key => $error_msg) {
@@ -305,6 +313,31 @@
             }
         } // end Fix record integrity
 
+
+//import files
+$files=CFile::getFileListLastVersionOnly($AppUI,0,$from_project_id,0);
+foreach ($files as $fileItem) {
+$newFile= new CFile;
+$file_id=$fileItem['latest_id'];
+$newFile->load($file_id);
+//goes into folder /0:
+$dest_realname=$newFile->duplicateFile($fileItem['file_project'],$fileItem['file_real_filename']);
+$newFile->file_real_filename=$dest_realname;
+//put into correct folder
+$newFile->file_project=$this->project_id;
+$newFile->moveFile(0,$newFile->file_real_filename);
+if ($newFile->file_task) $newFile->file_task= $newInd[$newFile->file_task];
+$newFile->file_id=0;
+$newFile->file_date=$AppUI->convertToUserTZ($newFile->file_date);//store converts bach to system TZ, so we need to set to user TZ first
+$newFile->file_parent=0; //we store only the very newest version of the file. For older version, look in the template
+$newFile->file_checkout=0;//even if checked out in template: we use the last version from the template that is/was valid
+//$newFile->file_owner=0; //don't change
+$newFile->file_version_id=$newFile->getNextFileVersionID();
+$newFile->store($AppUI);
+}
+
+
+
         // We have errors, so rollback everything we've done so far
         if (count($errors)) {
             $this->delete($AppUI);
+Notes

-Issue History
Date Modified Username Field Change
2011-03-09 12:03 opto New Issue
2011-03-09 12:26 opto Note Added: 0001720
2011-03-09 12:26 opto Assigned To => caseydk
2011-03-09 12:26 opto Status new => feedback
2011-03-09 12:27 opto Note Edited: 0001720
2011-03-12 04:00 opto Note Added: 0001721
2011-03-16 21:59 caseydk Project v2.2 Release (Closed) => v2.3 Release (Closed)
2011-03-23 00:07 caseydk Project v2.3 Release (Closed) => v2.4 Release (Closed)
2011-06-25 23:28 caseydk Project v2.4 Release (Closed) => Pending Requests
2014-08-16 18:53 caseydk Category General => Tasks
2014-08-16 18:53 caseydk Product Version 2.2 =>
+Issue History