ILIAS  release_7 Revision v7.30-3-g800a261c036
All Data Structures Namespaces Files Functions Variables Modules Pages
ilWikiUserHTMLExport Class Reference

Class manages user html export. More...

+ Collaboration diagram for ilWikiUserHTMLExport:

Public Member Functions

 __construct (ilObjWiki $a_wiki, ilDBInterface $a_db, ilObjUser $a_user, $with_comments=false)
 Construct. More...
 
 updateStatus ($a_progress, $a_status)
 Update status. More...
 
 getProgress ()
 Get Progress. More...
 
 initUserHTMLExport ()
 Init user html export. More...
 
 startUserHTMLExport ()
 Start user html export. More...
 
 deliverFile ()
 Deliver file. More...
 

Data Fields

const PROCESS_OTHER_USER = 0
 
const PROCESS_STARTED = 1
 
const PROCESS_UPTODATE = 2
 
const NOT_RUNNING = 0
 
const RUNNING = 1
 

Protected Member Functions

 read ()
 Read. More...
 
 getProcess ()
 Get process. More...
 
 doesFileExist ()
 Does file exist? More...
 

Protected Attributes

 $data
 
 $db
 
 $wiki
 
 $user
 
 $log
 
 $with_comments = false
 

Detailed Description

Class manages user html export.

Author
Alex Killing alex..nosp@m.kill.nosp@m.ing@g.nosp@m.mx.d.nosp@m.e

Definition at line 12 of file class.ilWikiUserHTMLExport.php.

Constructor & Destructor Documentation

◆ __construct()

ilWikiUserHTMLExport::__construct ( ilObjWiki  $a_wiki,
ilDBInterface  $a_db,
ilObjUser  $a_user,
  $with_comments = false 
)

Construct.

Parameters

Definition at line 55 of file class.ilWikiUserHTMLExport.php.

References $with_comments, ilLoggerFactory\getLogger(), read(), and user().

56  {
57  $this->db = $a_db;
58  $this->wiki = $a_wiki;
59  $this->user = $a_user;
60  $this->read();
61  $this->log = ilLoggerFactory::getLogger('wiki');
62  $this->with_comments = $with_comments;
63  $this->log->debug("comments: " . $this->with_comments);
64  }
user()
Definition: user.php:4
static getLogger($a_component_id)
Get component logger.
+ Here is the call graph for this function:

Member Function Documentation

◆ deliverFile()

ilWikiUserHTMLExport::deliverFile ( )

Deliver file.

Definition at line 250 of file class.ilWikiUserHTMLExport.php.

References ilUtil\deliverFile().

251  {
252  $this->log->debug("deliver");
253 
254  $exp = new WikiHtmlExport($this->wiki);
255  if ($this->with_comments) {
256  $exp->setMode(WikiHtmlExport::MODE_USER_COMMENTS);
257  } else {
258  $exp->setMode(WikiHtmlExport::MODE_USER);
259  }
260  $file = $exp->getUserExportFile();
261  $this->log->debug("file: " . $file);
262  ilUtil::deliverFile($file, pathinfo($file, PATHINFO_BASENAME));
263  }
Wiki HTML exporter class.
static deliverFile( $a_file, $a_filename, $a_mime='', $isInline=false, $removeAfterDelivery=false, $a_exit_after=true)
deliver file for download via browser.
+ Here is the call graph for this function:

◆ doesFileExist()

ilWikiUserHTMLExport::doesFileExist ( )
protected

Does file exist?

Definition at line 235 of file class.ilWikiUserHTMLExport.php.

Referenced by getProcess().

236  {
237  $exp = new WikiHtmlExport($this->wiki);
238  if ($this->with_comments) {
239  $exp->setMode(WikiHtmlExport::MODE_USER_COMMENTS);
240  } else {
241  $exp->setMode(WikiHtmlExport::MODE_USER);
242  }
243  $file = $exp->getUserExportFile();
244  return is_file($file);
245  }
Wiki HTML exporter class.
+ Here is the caller graph for this function:

◆ getProcess()

ilWikiUserHTMLExport::getProcess ( )
protected

Get process.

Parameters

Definition at line 90 of file class.ilWikiUserHTMLExport.php.

References $ilDB, $ret, $with_comments, doesFileExist(), ilPageObject\getLastChangeByParent(), ilDBInterface\manipulate(), ilUtil\now(), ilDBInterface\quote(), read(), and user().

Referenced by initUserHTMLExport().

91  {
92  $this->log->debug("getProcess");
93  $last_change = ilPageObject::getLastChangeByParent("wpg", $this->wiki->getId());
94  $file_exists = $this->doesFileExist();
95 
96  $ilAtomQuery = $this->db->buildAtomQuery();
97  $ilAtomQuery->addTableLock('wiki_user_html_export');
98 
99  $ilAtomQuery->addQueryCallable(function (ilDBInterface $ilDB) use ($last_change, &$ret, $file_exists) {
100  $this->log->debug("atom query start");
101 
102  $this->read();
103  $ts = ilUtil::now();
104 
105  if ($this->data["start_ts"] != "" &&
106  $this->data["start_ts"] > $last_change) {
107  if ($file_exists) {
108  $ret = self::PROCESS_UPTODATE;
109  $this->log->debug("return: " . self::PROCESS_UPTODATE);
110  return;
111  }
112  }
113 
114  if (!isset($this->data["wiki_id"])) {
115  $this->log->debug("insert, wiki id: " . $this->wiki->getId() . ", user id: " . $this->user->getId() .
116  ", ts: " . $ts . ", with_comments: " . $this->with_comments);
117  $ilDB->manipulate("INSERT INTO wiki_user_html_export " .
118  "(wiki_id, usr_id, progress, start_ts, status, with_comments) VALUES (" .
119  $ilDB->quote($this->wiki->getId(), "integer") . "," .
120  $ilDB->quote($this->user->getId(), "integer") . "," .
121  $ilDB->quote(0, "integer") . "," .
122  $ilDB->quote($ts, "timestamp") . "," .
123  $ilDB->quote(self::RUNNING, "integer") . "," .
124  $ilDB->quote($this->with_comments, "integer") .
125  ")");
126  } else {
127  $this->log->debug("update, wiki id: " . $this->wiki->getId() . ", user id: " . $this->user->getId() .
128  ", ts: " . $ts . ", with_comments: " . $this->with_comments);
129  $ilDB->manipulate(
130  "UPDATE wiki_user_html_export SET " .
131  " start_ts = " . $ilDB->quote($ts, "timestamp") . "," .
132  " usr_id = " . $ilDB->quote($this->user->getId(), "integer") . "," .
133  " progress = " . $ilDB->quote(0, "integer") . "," .
134  " status = " . $ilDB->quote(self::RUNNING, "integer") .
135  " WHERE status = " . $ilDB->quote(self::NOT_RUNNING, "integer") .
136  " AND wiki_id = " . $ilDB->quote($this->wiki->getId(), "integer") .
137  " AND with_comments = " . $ilDB->quote($this->with_comments, "integer")
138  );
139  $this->read();
140  }
141 
142  if ($this->data["start_ts"] == $ts && $this->data["usr_id"] == $this->user->getId()) {
143  // we started the process
144  $ret = self::PROCESS_STARTED;
145  $this->log->debug("return: " . self::PROCESS_STARTED);
146  return;
147  }
148 
149  // process was already running
150  $ret = self::PROCESS_OTHER_USER;
151  $this->log->debug("return: " . self::PROCESS_OTHER_USER);
152  });
153 
154  $ilAtomQuery->run();
155 
156  $this->log->debug("outer return: " . $ret);
157 
158  return $ret;
159  }
static getLastChangeByParent($a_parent_type, $a_parent_id, $a_lang="")
Get all pages for parent object.
static now()
Return current timestamp in Y-m-d H:i:s format.
user()
Definition: user.php:4
quote($value, $type)
global $ilDB
$ret
Definition: parser.php:6
manipulate($query)
Run a (write) Query on the database.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getProgress()

ilWikiUserHTMLExport::getProgress ( )

Get Progress.

Parameters

Definition at line 187 of file class.ilWikiUserHTMLExport.php.

188  {
189  $set = $this->db->query(
190  "SELECT progress, status FROM wiki_user_html_export " .
191  " WHERE wiki_id = " . $this->db->quote($this->wiki->getId(), "integer") .
192  " AND with_comments = " . $this->db->quote($this->with_comments, "integer")
193  );
194  $rec = $this->db->fetchAssoc($set);
195 
196  return array("progress" => (int) $rec["progress"], "status" => (int) $rec["status"]);
197  }

◆ initUserHTMLExport()

ilWikiUserHTMLExport::initUserHTMLExport ( )

Init user html export.

Parameters

Definition at line 206 of file class.ilWikiUserHTMLExport.php.

References exit, and getProcess().

207  {
208  // get process, if not already running or export is up-to-date, return corresponding status
209  echo $this->getProcess();
210  exit;
211  }
exit
Definition: login.php:29
+ Here is the call graph for this function:

◆ read()

ilWikiUserHTMLExport::read ( )
protected

Read.

Parameters

Definition at line 72 of file class.ilWikiUserHTMLExport.php.

Referenced by __construct(), getProcess(), and updateStatus().

73  {
74  $set = $this->db->query(
75  "SELECT * FROM wiki_user_html_export " .
76  " WHERE wiki_id = " . $this->db->quote($this->wiki->getId(), "integer") .
77  " AND with_comments = " . $this->db->quote($this->with_comments, "integer")
78  );
79  if (!$this->data = $this->db->fetchAssoc($set)) {
80  $this->data = array();
81  }
82  }
+ Here is the caller graph for this function:

◆ startUserHTMLExport()

ilWikiUserHTMLExport::startUserHTMLExport ( )

Start user html export.

Definition at line 216 of file class.ilWikiUserHTMLExport.php.

References exit, and updateStatus().

217  {
218  ignore_user_abort(true);
219  // do the export
220  $exp = new WikiHtmlExport($this->wiki);
221  if (!$this->with_comments) {
222  $exp->setMode(WikiHtmlExport::MODE_USER);
223  } else {
224  $exp->setMode(WikiHtmlExport::MODE_USER_COMMENTS);
225  }
226  $exp->buildExportFile();
227  // reset user export status
228  $this->updateStatus(100, self::NOT_RUNNING);
229  exit;
230  }
exit
Definition: login.php:29
updateStatus($a_progress, $a_status)
Update status.
Wiki HTML exporter class.
+ Here is the call graph for this function:

◆ updateStatus()

ilWikiUserHTMLExport::updateStatus (   $a_progress,
  $a_status 
)

Update status.

Parameters

Definition at line 167 of file class.ilWikiUserHTMLExport.php.

References read().

Referenced by startUserHTMLExport().

168  {
169  $this->db->manipulate(
170  "UPDATE wiki_user_html_export SET " .
171  " progress = " . $this->db->quote((int) $a_progress, "integer") . "," .
172  " status = " . $this->db->quote((int) $a_status, "integer") .
173  " WHERE wiki_id = " . $this->db->quote($this->wiki->getId(), "integer") .
174  " AND usr_id = " . $this->db->quote($this->user->getId(), "integer") .
175  " AND with_comments = " . $this->db->quote($this->with_comments, "integer")
176  );
177 
178  $this->read();
179  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Field Documentation

◆ $data

ilWikiUserHTMLExport::$data
protected

Definition at line 22 of file class.ilWikiUserHTMLExport.php.

◆ $db

ilWikiUserHTMLExport::$db
protected

Definition at line 27 of file class.ilWikiUserHTMLExport.php.

◆ $log

ilWikiUserHTMLExport::$log
protected

Definition at line 42 of file class.ilWikiUserHTMLExport.php.

◆ $user

ilWikiUserHTMLExport::$user
protected

Definition at line 37 of file class.ilWikiUserHTMLExport.php.

◆ $wiki

ilWikiUserHTMLExport::$wiki
protected

Definition at line 32 of file class.ilWikiUserHTMLExport.php.

◆ $with_comments

ilWikiUserHTMLExport::$with_comments = false
protected

Definition at line 47 of file class.ilWikiUserHTMLExport.php.

Referenced by __construct(), and getProcess().

◆ NOT_RUNNING

const ilWikiUserHTMLExport::NOT_RUNNING = 0

Definition at line 19 of file class.ilWikiUserHTMLExport.php.

◆ PROCESS_OTHER_USER

const ilWikiUserHTMLExport::PROCESS_OTHER_USER = 0

Definition at line 14 of file class.ilWikiUserHTMLExport.php.

◆ PROCESS_STARTED

const ilWikiUserHTMLExport::PROCESS_STARTED = 1

Definition at line 15 of file class.ilWikiUserHTMLExport.php.

◆ PROCESS_UPTODATE

const ilWikiUserHTMLExport::PROCESS_UPTODATE = 2

Definition at line 16 of file class.ilWikiUserHTMLExport.php.

◆ RUNNING


The documentation for this class was generated from the following file: