| 15 |
***************************************************************************/ |
***************************************************************************/ |
| 16 |
|
|
| 17 |
#include "section_list_loader.h" |
#include "section_list_loader.h" |
| 18 |
|
#include "article_cache.h" |
| 19 |
#include "log.h" |
#include "log.h" |
| 20 |
#include "database.h" |
#include "database.h" |
| 21 |
#include "menu.h" |
#include "menu.h" |
| 181 |
} |
} |
| 182 |
|
|
| 183 |
snprintf(sql, sizeof(sql), |
snprintf(sql, sizeof(sql), |
| 184 |
"SELECT AID, TID, SID, CID, UID, visible, excerption, ontop, `lock`, " |
"SELECT bbs.AID, TID, SID, bbs.CID, UID, visible, excerption, ontop, `lock`, " |
| 185 |
"transship, username, nickname, title, UNIX_TIMESTAMP(sub_dt) AS sub_dt " |
"transship, username, nickname, title, UNIX_TIMESTAMP(sub_dt) AS sub_dt, " |
| 186 |
"FROM bbs WHERE AID >= %d ORDER BY AID LIMIT %d", |
"bbs_content.content " |
| 187 |
|
"FROM bbs INNER JOIN bbs_content ON bbs.CID = bbs_content.CID " |
| 188 |
|
"WHERE bbs.AID >= %d ORDER BY bbs.AID LIMIT %d", |
| 189 |
start_aid, article_count_limit); |
start_aid, article_count_limit); |
| 190 |
|
|
| 191 |
if (mysql_query(db, sql) != 0) |
if (mysql_query(db, sql) != 0) |
| 193 |
log_error("Query article list error: %s\n", mysql_error(db)); |
log_error("Query article list error: %s\n", mysql_error(db)); |
| 194 |
return -3; |
return -3; |
| 195 |
} |
} |
| 196 |
if ((rs = mysql_store_result(db)) == NULL) |
if ((rs = mysql_use_result(db)) == NULL) |
| 197 |
{ |
{ |
| 198 |
log_error("Get article list data failed\n"); |
log_error("Get article list data failed\n"); |
| 199 |
return -3; |
return -3; |
| 241 |
{ |
{ |
| 242 |
if ((ret = section_list_rw_unlock(p_section)) < 0) |
if ((ret = section_list_rw_unlock(p_section)) < 0) |
| 243 |
{ |
{ |
| 244 |
log_error("section_list_rw_unlock(sid = %d) error\n", p_section->sid); |
log_error("section_list_rw_unlock(sid=%d) error\n", p_section->sid); |
| 245 |
break; |
break; |
| 246 |
} |
} |
| 247 |
} |
} |
| 270 |
{ |
{ |
| 271 |
if ((ret = section_list_rw_lock(p_section)) < 0) |
if ((ret = section_list_rw_lock(p_section)) < 0) |
| 272 |
{ |
{ |
| 273 |
log_error("section_list_rw_lock(sid = 0) error\n"); |
log_error("section_list_rw_lock(sid=0) error\n"); |
| 274 |
break; |
break; |
| 275 |
} |
} |
| 276 |
} |
} |
| 280 |
|
|
| 281 |
if (section_list_append_article(p_section, &article) < 0) |
if (section_list_append_article(p_section, &article) < 0) |
| 282 |
{ |
{ |
| 283 |
log_error("section_list_append_article(sid = %d, aid = %d) error\n", |
log_error("section_list_append_article(sid=%d, aid=%d) error\n", |
| 284 |
p_section->sid, article.aid); |
p_section->sid, article.aid); |
| 285 |
ret = -3; |
ret = -3; |
| 286 |
break; |
break; |
| 288 |
|
|
| 289 |
article_count++; |
article_count++; |
| 290 |
|
|
| 291 |
// TODO: generate content cache |
if (article_cache_generate(VAR_ARTICLE_CACHE_DIR, &article, row[i++], 0) < 0) |
| 292 |
|
{ |
| 293 |
|
log_error("article_cache_generate(aid=%d, cid=%d) error\n", article.aid, article.cid); |
| 294 |
|
ret = -4; |
| 295 |
|
break; |
| 296 |
|
} |
| 297 |
} |
} |
| 298 |
|
|
| 299 |
// release lock of last section |
// release lock of last section |
| 301 |
{ |
{ |
| 302 |
if ((ret = section_list_rw_unlock(p_section)) < 0) |
if ((ret = section_list_rw_unlock(p_section)) < 0) |
| 303 |
{ |
{ |
| 304 |
log_error("section_list_rw_unlock(sid = %d) error\n", p_section->sid); |
log_error("section_list_rw_unlock(sid=%d) error\n", p_section->sid); |
| 305 |
} |
} |
| 306 |
} |
} |
| 307 |
|
|
| 310 |
{ |
{ |
| 311 |
if ((ret = section_list_rw_unlock(NULL)) < 0) |
if ((ret = section_list_rw_unlock(NULL)) < 0) |
| 312 |
{ |
{ |
| 313 |
log_error("section_list_rw_unlock(sid = 0) error\n"); |
log_error("section_list_rw_unlock(sid=0) error\n"); |
| 314 |
} |
} |
| 315 |
} |
} |
| 316 |
|
|
| 467 |
break; |
break; |
| 468 |
case 'M': // Modify article |
case 'M': // Modify article |
| 469 |
snprintf(sql, sizeof(sql), |
snprintf(sql, sizeof(sql), |
| 470 |
"SELECT CID FROM bbs WHERE AID = %d", |
"SELECT bbs.CID, bbs_content.content " |
| 471 |
|
"FROM bbs INNER JOIN bbs_content ON bbs.CID = bbs_content.CID " |
| 472 |
|
"WHERE bbs.AID = %d", |
| 473 |
p_article->aid); |
p_article->aid); |
| 474 |
|
|
| 475 |
if (mysql_query(db, sql) != 0) |
if (mysql_query(db, sql) != 0) |
| 478 |
ret = -3; |
ret = -3; |
| 479 |
break; |
break; |
| 480 |
} |
} |
| 481 |
if ((rs2 = mysql_store_result(db)) == NULL) |
if ((rs2 = mysql_use_result(db)) == NULL) |
| 482 |
{ |
{ |
| 483 |
log_error("Get article data failed\n"); |
log_error("Get article data failed\n"); |
| 484 |
ret = -3; |
ret = -3; |
| 487 |
if ((row2 = mysql_fetch_row(rs2))) |
if ((row2 = mysql_fetch_row(rs2))) |
| 488 |
{ |
{ |
| 489 |
p_article->cid = atoi(row2[0]); |
p_article->cid = atoi(row2[0]); |
| 490 |
|
|
| 491 |
|
if (article_cache_generate(VAR_ARTICLE_CACHE_DIR, p_article, row2[1], 0) < 0) |
| 492 |
|
{ |
| 493 |
|
log_error("article_cache_generate(aid=%d, cid=%d) error\n", p_article->aid, p_article->cid); |
| 494 |
|
ret = -4; |
| 495 |
|
} |
| 496 |
} |
} |
| 497 |
else |
else |
| 498 |
{ |
{ |
| 500 |
ret = -4; |
ret = -4; |
| 501 |
} |
} |
| 502 |
mysql_free_result(rs2); |
mysql_free_result(rs2); |
|
|
|
|
if (p_article->cid > 0) |
|
|
{ |
|
|
// TODO: generate content cache |
|
|
} |
|
|
|
|
| 503 |
break; |
break; |
| 504 |
case 'T': // Move article |
case 'T': // Move article |
| 505 |
snprintf(sql, sizeof(sql), |
snprintf(sql, sizeof(sql), |